Commit b9c28286 authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by David S. Miller

nfc: constify nci_ops

The struct nci_ops is modified by NFC core in only one case:
nci_allocate_device() receives too many proprietary commands (prop_ops)
to configure.  This is a build time known constrain, so a graceful
handling of such case is not necessary.

Instead, fail the nci_allocate_device() and add BUILD_BUG_ON() to places
which set these.

This allows to constify the struct nci_ops (consisting of function
pointers) for correctness and safety.
Signed-off-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 48d54403
...@@ -675,7 +675,7 @@ static struct nci_driver_ops fdp_prop_ops[] = { ...@@ -675,7 +675,7 @@ static struct nci_driver_ops fdp_prop_ops[] = {
}, },
}; };
static struct nci_ops nci_ops = { static const struct nci_ops nci_ops = {
.open = fdp_nci_open, .open = fdp_nci_open,
.close = fdp_nci_close, .close = fdp_nci_close,
.send = fdp_nci_send, .send = fdp_nci_send,
...@@ -718,6 +718,7 @@ int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops, ...@@ -718,6 +718,7 @@ int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops,
NFC_PROTO_NFC_DEP_MASK | NFC_PROTO_NFC_DEP_MASK |
NFC_PROTO_ISO15693_MASK; NFC_PROTO_ISO15693_MASK;
BUILD_BUG_ON(ARRAY_SIZE(fdp_prop_ops) > NCI_MAX_PROPRIETARY_CMD);
ndev = nci_allocate_device(&nci_ops, protocols, tx_headroom, ndev = nci_allocate_device(&nci_ops, protocols, tx_headroom,
tx_tailroom); tx_tailroom);
if (!ndev) { if (!ndev) {
......
...@@ -81,7 +81,7 @@ static int nfcmrvl_nci_fw_download(struct nci_dev *ndev, ...@@ -81,7 +81,7 @@ static int nfcmrvl_nci_fw_download(struct nci_dev *ndev,
return nfcmrvl_fw_dnld_start(ndev, firmware_name); return nfcmrvl_fw_dnld_start(ndev, firmware_name);
} }
static struct nci_ops nfcmrvl_nci_ops = { static const struct nci_ops nfcmrvl_nci_ops = {
.open = nfcmrvl_nci_open, .open = nfcmrvl_nci_open,
.close = nfcmrvl_nci_close, .close = nfcmrvl_nci_close,
.send = nfcmrvl_nci_send, .send = nfcmrvl_nci_send,
......
...@@ -83,7 +83,7 @@ static int nxp_nci_send(struct nci_dev *ndev, struct sk_buff *skb) ...@@ -83,7 +83,7 @@ static int nxp_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
return r; return r;
} }
static struct nci_ops nxp_nci_ops = { static const struct nci_ops nxp_nci_ops = {
.open = nxp_nci_open, .open = nxp_nci_open,
.close = nxp_nci_close, .close = nxp_nci_close,
.send = nxp_nci_send, .send = nxp_nci_send,
......
...@@ -94,7 +94,7 @@ static struct nci_driver_ops st_nci_prop_ops[] = { ...@@ -94,7 +94,7 @@ static struct nci_driver_ops st_nci_prop_ops[] = {
}, },
}; };
static struct nci_ops st_nci_ops = { static const struct nci_ops st_nci_ops = {
.init = st_nci_init, .init = st_nci_init,
.open = st_nci_open, .open = st_nci_open,
.close = st_nci_close, .close = st_nci_close,
...@@ -131,6 +131,7 @@ int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom, ...@@ -131,6 +131,7 @@ int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
| NFC_PROTO_ISO15693_MASK | NFC_PROTO_ISO15693_MASK
| NFC_PROTO_NFC_DEP_MASK; | NFC_PROTO_NFC_DEP_MASK;
BUILD_BUG_ON(ARRAY_SIZE(st_nci_prop_ops) > NCI_MAX_PROPRIETARY_CMD);
ndlc->ndev = nci_allocate_device(&st_nci_ops, protocols, ndlc->ndev = nci_allocate_device(&st_nci_ops, protocols,
phy_headroom, phy_tailroom); phy_headroom, phy_tailroom);
if (!ndlc->ndev) { if (!ndlc->ndev) {
......
...@@ -65,7 +65,7 @@ static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb) ...@@ -65,7 +65,7 @@ static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
return 0; return 0;
} }
static struct nci_ops virtual_nci_ops = { static const struct nci_ops virtual_nci_ops = {
.open = virtual_nci_open, .open = virtual_nci_open,
.close = virtual_nci_close, .close = virtual_nci_close,
.send = virtual_nci_send .send = virtual_nci_send
......
...@@ -194,7 +194,7 @@ struct nci_hci_dev { ...@@ -194,7 +194,7 @@ struct nci_hci_dev {
/* NCI Core structures */ /* NCI Core structures */
struct nci_dev { struct nci_dev {
struct nfc_dev *nfc_dev; struct nfc_dev *nfc_dev;
struct nci_ops *ops; const struct nci_ops *ops;
struct nci_hci_dev *hci_dev; struct nci_hci_dev *hci_dev;
int tx_headroom; int tx_headroom;
...@@ -267,7 +267,7 @@ struct nci_dev { ...@@ -267,7 +267,7 @@ struct nci_dev {
}; };
/* ----- NCI Devices ----- */ /* ----- NCI Devices ----- */
struct nci_dev *nci_allocate_device(struct nci_ops *ops, struct nci_dev *nci_allocate_device(const struct nci_ops *ops,
__u32 supported_protocols, __u32 supported_protocols,
int tx_headroom, int tx_headroom,
int tx_tailroom); int tx_tailroom);
......
...@@ -1129,7 +1129,7 @@ static struct nfc_ops nci_nfc_ops = { ...@@ -1129,7 +1129,7 @@ static struct nfc_ops nci_nfc_ops = {
* @tx_headroom: Reserved space at beginning of skb * @tx_headroom: Reserved space at beginning of skb
* @tx_tailroom: Reserved space at end of skb * @tx_tailroom: Reserved space at end of skb
*/ */
struct nci_dev *nci_allocate_device(struct nci_ops *ops, struct nci_dev *nci_allocate_device(const struct nci_ops *ops,
__u32 supported_protocols, __u32 supported_protocols,
int tx_headroom, int tx_tailroom) int tx_headroom, int tx_tailroom)
{ {
...@@ -1152,8 +1152,7 @@ struct nci_dev *nci_allocate_device(struct nci_ops *ops, ...@@ -1152,8 +1152,7 @@ struct nci_dev *nci_allocate_device(struct nci_ops *ops,
if (ops->n_prop_ops > NCI_MAX_PROPRIETARY_CMD) { if (ops->n_prop_ops > NCI_MAX_PROPRIETARY_CMD) {
pr_err("Too many proprietary commands: %zd\n", pr_err("Too many proprietary commands: %zd\n",
ops->n_prop_ops); ops->n_prop_ops);
ops->prop_ops = NULL; goto free_nci;
ops->n_prop_ops = 0;
} }
ndev->tx_headroom = tx_headroom; ndev->tx_headroom = tx_headroom;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment