diff options
Diffstat (limited to 'drivers/nfc')
| -rw-r--r-- | drivers/nfc/mei_phy.c | 2 | ||||
| -rw-r--r-- | drivers/nfc/microread/i2c.c | 1 | ||||
| -rw-r--r-- | drivers/nfc/microread/microread.c | 4 | ||||
| -rw-r--r-- | drivers/nfc/nfcmrvl/fw_dnld.c | 2 | ||||
| -rw-r--r-- | drivers/nfc/nfcmrvl/main.c | 49 | ||||
| -rw-r--r-- | drivers/nfc/nfcmrvl/nfcmrvl.h | 4 | ||||
| -rw-r--r-- | drivers/nfc/nfcmrvl/uart.c | 23 | ||||
| -rw-r--r-- | drivers/nfc/nfcmrvl/usb.c | 22 | ||||
| -rw-r--r-- | drivers/nfc/nfcsim.c | 4 | ||||
| -rw-r--r-- | drivers/nfc/nxp-nci/firmware.c | 2 | ||||
| -rw-r--r-- | drivers/nfc/nxp-nci/i2c.c | 6 | ||||
| -rw-r--r-- | drivers/nfc/pn533/pn533.c | 10 | ||||
| -rw-r--r-- | drivers/nfc/pn533/uart.c | 16 | ||||
| -rw-r--r-- | drivers/nfc/pn533/usb.c | 37 | ||||
| -rw-r--r-- | drivers/nfc/pn544/i2c.c | 2 | ||||
| -rw-r--r-- | drivers/nfc/pn544/pn544.c | 2 | ||||
| -rw-r--r-- | drivers/nfc/port100.c | 39 | ||||
| -rw-r--r-- | drivers/nfc/s3fwrn5/firmware.c | 2 | ||||
| -rw-r--r-- | drivers/nfc/s3fwrn5/i2c.c | 54 | ||||
| -rw-r--r-- | drivers/nfc/s3fwrn5/phy_common.c | 11 | ||||
| -rw-r--r-- | drivers/nfc/s3fwrn5/phy_common.h | 5 | ||||
| -rw-r--r-- | drivers/nfc/s3fwrn5/uart.c | 53 | ||||
| -rw-r--r-- | drivers/nfc/st21nfca/core.c | 2 | ||||
| -rw-r--r-- | drivers/nfc/trf7970a.c | 3 | ||||
| -rw-r--r-- | drivers/nfc/virtual_ncidev.c | 6 |
25 files changed, 130 insertions, 231 deletions
diff --git a/drivers/nfc/mei_phy.c b/drivers/nfc/mei_phy.c index f9cca885beec..0ea28597e6f5 100644 --- a/drivers/nfc/mei_phy.c +++ b/drivers/nfc/mei_phy.c @@ -373,7 +373,7 @@ struct nfc_mei_phy *nfc_mei_phy_alloc(struct mei_cl_device *cldev) { struct nfc_mei_phy *phy; - phy = kzalloc(sizeof(struct nfc_mei_phy), GFP_KERNEL); + phy = kzalloc_obj(struct nfc_mei_phy); if (!phy) return NULL; diff --git a/drivers/nfc/microread/i2c.c b/drivers/nfc/microread/i2c.c index 113b2e306e35..f00cff7f9693 100644 --- a/drivers/nfc/microread/i2c.c +++ b/drivers/nfc/microread/i2c.c @@ -12,7 +12,6 @@ #include <linux/delay.h> #include <linux/slab.h> #include <linux/interrupt.h> -#include <linux/gpio.h> #include <linux/nfc.h> #include <net/nfc/hci.h> diff --git a/drivers/nfc/microread/microread.c b/drivers/nfc/microread/microread.c index bb4d029bb888..4149c5d735bd 100644 --- a/drivers/nfc/microread/microread.c +++ b/drivers/nfc/microread/microread.c @@ -473,7 +473,7 @@ static void microread_target_discovered(struct nfc_hci_dev *hdev, u8 gate, pr_info("target discovered to gate 0x%x\n", gate); - targets = kzalloc(sizeof(struct nfc_target), GFP_KERNEL); + targets = kzalloc_obj(struct nfc_target); if (targets == NULL) { r = -ENOMEM; goto exit; @@ -650,7 +650,7 @@ int microread_probe(void *phy_id, const struct nfc_phy_ops *phy_ops, struct nfc_hci_init_data init_data; int r; - info = kzalloc(sizeof(struct microread_info), GFP_KERNEL); + info = kzalloc_obj(struct microread_info); if (!info) { r = -ENOMEM; goto err_info_alloc; diff --git a/drivers/nfc/nfcmrvl/fw_dnld.c b/drivers/nfc/nfcmrvl/fw_dnld.c index a9b03dcc4100..2b8f401d8fd7 100644 --- a/drivers/nfc/nfcmrvl/fw_dnld.c +++ b/drivers/nfc/nfcmrvl/fw_dnld.c @@ -492,7 +492,7 @@ int nfcmrvl_fw_dnld_start(struct nci_dev *ndev, const char *firmware_name) if (!firmware_name || !firmware_name[0]) return -EINVAL; - strcpy(fw_dnld->name, firmware_name); + strscpy(fw_dnld->name, firmware_name); /* * Retrieve FW binary file and parse it to initialize FW download diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c index 141bc4b66dcb..6efa83219117 100644 --- a/drivers/nfc/nfcmrvl/main.c +++ b/drivers/nfc/nfcmrvl/main.c @@ -6,9 +6,9 @@ */ #include <linux/module.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/delay.h> -#include <linux/of_gpio.h> +#include <linux/of.h> #include <linux/nfc.h> #include <net/nfc/nci.h> #include <net/nfc/nci_core.h> @@ -101,7 +101,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, int tailroom; u32 protocols; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = kzalloc_obj(*priv); if (!priv) return ERR_PTR(-ENOMEM); @@ -112,13 +112,12 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, memcpy(&priv->config, pdata, sizeof(*pdata)); - if (gpio_is_valid(priv->config.reset_n_io)) { - rc = gpio_request_one(priv->config.reset_n_io, - GPIOF_OUT_INIT_LOW, - "nfcmrvl_reset_n"); - if (rc < 0) { - priv->config.reset_n_io = -EINVAL; - nfc_err(dev, "failed to request reset_n io\n"); + if (!priv->config.reset_gpio) { + priv->config.reset_gpio = + devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(priv->config.reset_gpio)) { + priv->config.reset_gpio = NULL; + nfc_err(dev, "failed to get reset gpio\n"); } } @@ -144,7 +143,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, if (!priv->ndev) { nfc_err(dev, "nci_allocate_device failed\n"); rc = -ENOMEM; - goto error_free_gpio; + goto error_free; } rc = nfcmrvl_fw_dnld_init(priv); @@ -171,9 +170,7 @@ error_fw_dnld_deinit: nfcmrvl_fw_dnld_deinit(priv); error_free_dev: nci_free_device(priv->ndev); -error_free_gpio: - if (gpio_is_valid(priv->config.reset_n_io)) - gpio_free(priv->config.reset_n_io); +error_free: kfree(priv); return ERR_PTR(rc); } @@ -189,9 +186,6 @@ void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv) nfcmrvl_fw_dnld_deinit(priv); - if (gpio_is_valid(priv->config.reset_n_io)) - gpio_free(priv->config.reset_n_io); - nci_free_device(ndev); kfree(priv); } @@ -233,34 +227,25 @@ void nfcmrvl_chip_reset(struct nfcmrvl_private *priv) /* Reset possible fault of previous session */ clear_bit(NFCMRVL_PHY_ERROR, &priv->flags); - if (gpio_is_valid(priv->config.reset_n_io)) { + if (priv->config.reset_gpio) { nfc_info(priv->dev, "reset the chip\n"); - gpio_set_value(priv->config.reset_n_io, 0); + gpiod_set_value(priv->config.reset_gpio, 1); usleep_range(5000, 10000); - gpio_set_value(priv->config.reset_n_io, 1); + gpiod_set_value(priv->config.reset_gpio, 0); } else nfc_info(priv->dev, "no reset available on this interface\n"); } void nfcmrvl_chip_halt(struct nfcmrvl_private *priv) { - if (gpio_is_valid(priv->config.reset_n_io)) - gpio_set_value(priv->config.reset_n_io, 0); + if (priv->config.reset_gpio) + gpiod_set_value(priv->config.reset_gpio, 1); } int nfcmrvl_parse_dt(struct device_node *node, struct nfcmrvl_platform_data *pdata) { - int reset_n_io; - - reset_n_io = of_get_named_gpio(node, "reset-n-io", 0); - if (reset_n_io < 0) { - pr_info("no reset-n-io config\n"); - } else if (!gpio_is_valid(reset_n_io)) { - pr_err("invalid reset-n-io GPIO\n"); - return reset_n_io; - } - pdata->reset_n_io = reset_n_io; + pdata->reset_gpio = NULL; pdata->hci_muxed = of_property_read_bool(node, "hci-muxed"); return 0; diff --git a/drivers/nfc/nfcmrvl/nfcmrvl.h b/drivers/nfc/nfcmrvl/nfcmrvl.h index f61a99e553db..62fa77d587b2 100644 --- a/drivers/nfc/nfcmrvl/nfcmrvl.h +++ b/drivers/nfc/nfcmrvl/nfcmrvl.h @@ -10,6 +10,8 @@ #include "fw_dnld.h" +struct gpio_desc; + /* Define private flags: */ #define NFCMRVL_NCI_RUNNING 1 #define NFCMRVL_PHY_ERROR 2 @@ -54,7 +56,7 @@ struct nfcmrvl_platform_data { */ /* GPIO that is wired to RESET_N signal */ - int reset_n_io; + struct gpio_desc *reset_gpio; /* Tell if transport is muxed in HCI one */ bool hci_muxed; diff --git a/drivers/nfc/nfcmrvl/uart.c b/drivers/nfc/nfcmrvl/uart.c index 2037cd6d4f4f..9aedd168759c 100644 --- a/drivers/nfc/nfcmrvl/uart.c +++ b/drivers/nfc/nfcmrvl/uart.c @@ -8,6 +8,7 @@ #include <linux/delay.h> #include <linux/device.h> #include <linux/err.h> +#include <linux/gpio/consumer.h> #include <linux/module.h> #include <linux/of.h> #include <linux/printk.h> @@ -20,7 +21,6 @@ static unsigned int hci_muxed; static unsigned int flow_control; static unsigned int break_control; -static int reset_n_io = -EINVAL; /* * NFCMRVL NCI OPS @@ -62,9 +62,11 @@ static const struct nfcmrvl_if_ops uart_ops = { }; static int nfcmrvl_uart_parse_dt(struct device_node *node, - struct nfcmrvl_platform_data *pdata) + struct nfcmrvl_platform_data *pdata, + struct device *dev) { struct device_node *matched_node; + struct gpio_desc *reset_gpio; int ret; matched_node = of_get_compatible_child(node, "marvell,nfc-uart"); @@ -84,6 +86,16 @@ static int nfcmrvl_uart_parse_dt(struct device_node *node, pdata->flow_control = of_property_read_bool(matched_node, "flow-control"); pdata->break_control = of_property_read_bool(matched_node, "break-control"); + reset_gpio = devm_fwnode_gpiod_get_optional(dev, + of_fwnode_handle(matched_node), + "reset", GPIOD_OUT_HIGH, + "nfcmrvl_reset_n"); + if (IS_ERR(reset_gpio)) { + of_node_put(matched_node); + return PTR_ERR(reset_gpio); + } + pdata->reset_gpio = reset_gpio; + of_node_put(matched_node); return 0; @@ -107,13 +119,13 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu) */ if (dev && dev->parent && dev->parent->of_node) - if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config) == 0) + if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config, dev) == 0) pdata = &config; if (!pdata) { pr_info("No platform data / DT -> fallback to module params\n"); config.hci_muxed = hci_muxed; - config.reset_n_io = reset_n_io; + config.reset_gpio = NULL; config.flow_control = flow_control; config.break_control = break_control; pdata = &config; @@ -201,6 +213,3 @@ MODULE_PARM_DESC(break_control, "Tell if UART driver must drive break signal."); module_param(hci_muxed, uint, 0); MODULE_PARM_DESC(hci_muxed, "Tell if transport is muxed in HCI one."); - -module_param(reset_n_io, int, 0); -MODULE_PARM_DESC(reset_n_io, "GPIO that is wired to RESET_N signal."); diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c index ea7309453096..4babde8e4249 100644 --- a/drivers/nfc/nfcmrvl/usb.c +++ b/drivers/nfc/nfcmrvl/usb.c @@ -288,13 +288,13 @@ static int nfcmrvl_probe(struct usb_interface *intf, { struct nfcmrvl_usb_drv_data *drv_data; struct nfcmrvl_private *priv; - int i; struct usb_device *udev = interface_to_usbdev(intf); struct nfcmrvl_platform_data config; + int ret; /* No configuration for USB */ memset(&config, 0, sizeof(config)); - config.reset_n_io = -EINVAL; + config.reset_gpio = NULL; nfc_info(&udev->dev, "intf %p id %p\n", intf, id); @@ -302,21 +302,9 @@ static int nfcmrvl_probe(struct usb_interface *intf, if (!drv_data) return -ENOMEM; - for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { - struct usb_endpoint_descriptor *ep_desc; - - ep_desc = &intf->cur_altsetting->endpoint[i].desc; - - if (!drv_data->bulk_tx_ep && - usb_endpoint_is_bulk_out(ep_desc)) { - drv_data->bulk_tx_ep = ep_desc; - } else if (!drv_data->bulk_rx_ep && - usb_endpoint_is_bulk_in(ep_desc)) { - drv_data->bulk_rx_ep = ep_desc; - } - } - - if (!drv_data->bulk_tx_ep || !drv_data->bulk_rx_ep) + ret = usb_find_common_endpoints(intf->cur_altsetting, &drv_data->bulk_rx_ep, + &drv_data->bulk_tx_ep, NULL, NULL); + if (ret) return -ENODEV; drv_data->udev = udev; diff --git a/drivers/nfc/nfcsim.c b/drivers/nfc/nfcsim.c index a55381f80cd6..f8e5c4da3b13 100644 --- a/drivers/nfc/nfcsim.c +++ b/drivers/nfc/nfcsim.c @@ -66,7 +66,7 @@ static struct nfcsim_link *nfcsim_link_new(void) { struct nfcsim_link *link; - link = kzalloc(sizeof(struct nfcsim_link), GFP_KERNEL); + link = kzalloc_obj(struct nfcsim_link); if (!link) return NULL; @@ -373,7 +373,7 @@ static struct nfcsim *nfcsim_device_new(struct nfcsim_link *link_in, struct nfcsim *dev; int rc; - dev = kzalloc(sizeof(struct nfcsim), GFP_KERNEL); + dev = kzalloc_obj(struct nfcsim); if (!dev) return ERR_PTR(-ENOMEM); diff --git a/drivers/nfc/nxp-nci/firmware.c b/drivers/nfc/nxp-nci/firmware.c index 381b5bb75477..a9533977aff8 100644 --- a/drivers/nfc/nxp-nci/firmware.c +++ b/drivers/nfc/nxp-nci/firmware.c @@ -211,7 +211,7 @@ int nxp_nci_fw_download(struct nci_dev *ndev, const char *firmware_name) goto fw_download_exit; } - strcpy(fw_info->name, firmware_name); + strscpy(fw_info->name, firmware_name); r = request_firmware(&fw_info->fw, firmware_name, ndev->nfc_dev->dev.parent); diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c index 049662ffdf97..b3d34433bd14 100644 --- a/drivers/nfc/nxp-nci/i2c.c +++ b/drivers/nfc/nxp-nci/i2c.c @@ -47,8 +47,8 @@ static int nxp_nci_i2c_set_mode(void *phy_id, { struct nxp_nci_i2c_phy *phy = (struct nxp_nci_i2c_phy *) phy_id; - gpiod_set_value(phy->gpiod_fw, (mode == NXP_NCI_MODE_FW) ? 1 : 0); - gpiod_set_value(phy->gpiod_en, (mode != NXP_NCI_MODE_COLD) ? 1 : 0); + gpiod_set_value_cansleep(phy->gpiod_fw, (mode == NXP_NCI_MODE_FW) ? 1 : 0); + gpiod_set_value_cansleep(phy->gpiod_en, (mode != NXP_NCI_MODE_COLD) ? 1 : 0); usleep_range(10000, 15000); if (mode == NXP_NCI_MODE_COLD) @@ -305,7 +305,7 @@ static int nxp_nci_i2c_probe(struct i2c_client *client) r = request_threaded_irq(client->irq, NULL, nxp_nci_i2c_irq_thread_fn, - IRQF_TRIGGER_RISING | IRQF_ONESHOT, + IRQF_ONESHOT, NXP_NCI_I2C_DRIVER_NAME, phy); if (r < 0) nfc_err(&client->dev, "Unable to register IRQ handler\n"); diff --git a/drivers/nfc/pn533/pn533.c b/drivers/nfc/pn533/pn533.c index 2b043a9f9533..d7bdbc82e2ba 100644 --- a/drivers/nfc/pn533/pn533.c +++ b/drivers/nfc/pn533/pn533.c @@ -444,7 +444,7 @@ static int __pn533_send_async(struct pn533 *dev, u8 cmd_code, dev_dbg(dev->dev, "Sending command 0x%x\n", cmd_code); - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); + cmd = kzalloc_obj(*cmd); if (!cmd) return -ENOMEM; @@ -518,7 +518,7 @@ static int pn533_send_cmd_direct_async(struct pn533 *dev, u8 cmd_code, struct pn533_cmd *cmd; int rc; - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); + cmd = kzalloc_obj(*cmd); if (!cmd) return -ENOMEM; @@ -2019,7 +2019,7 @@ static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target, *next = 0; } - arg = kmalloc(sizeof(*arg), GFP_KERNEL); + arg = kmalloc_obj(*arg); if (!arg) { dev_kfree_skb(skb); return -ENOMEM; @@ -2266,7 +2266,7 @@ static int pn533_transceive(struct nfc_dev *nfc_dev, goto error; } - arg = kmalloc(sizeof(*arg), GFP_KERNEL); + arg = kmalloc_obj(*arg); if (!arg) { rc = -ENOMEM; goto error; @@ -2744,7 +2744,7 @@ struct pn533 *pn53x_common_init(u32 device_type, { struct pn533 *priv; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = kzalloc_obj(*priv); if (!priv) return ERR_PTR(-ENOMEM); diff --git a/drivers/nfc/pn533/uart.c b/drivers/nfc/pn533/uart.c index a081bce61c29..e0d67cd2ac9b 100644 --- a/drivers/nfc/pn533/uart.c +++ b/drivers/nfc/pn533/uart.c @@ -211,14 +211,22 @@ static size_t pn532_receive_buf(struct serdev_device *serdev, timer_delete(&dev->cmd_timeout); for (i = 0; i < count; i++) { + if (!dev->recv_skb) { + dev->recv_skb = alloc_skb(PN532_UART_SKB_BUFF_LEN, + GFP_KERNEL); + if (!dev->recv_skb) + return i; + } + + if (unlikely(!skb_tailroom(dev->recv_skb))) + skb_trim(dev->recv_skb, 0); + skb_put_u8(dev->recv_skb, *data++); if (!pn532_uart_rx_is_frame(dev->recv_skb)) continue; pn533_recv_frame(dev->priv, dev->recv_skb, 0); - dev->recv_skb = alloc_skb(PN532_UART_SKB_BUFF_LEN, GFP_KERNEL); - if (!dev->recv_skb) - return 0; + dev->recv_skb = NULL; } return i; @@ -242,7 +250,7 @@ static int pn532_uart_probe(struct serdev_device *serdev) int err; err = -ENOMEM; - pn532 = kzalloc(sizeof(*pn532), GFP_KERNEL); + pn532 = kzalloc_obj(*pn532); if (!pn532) goto err_exit; diff --git a/drivers/nfc/pn533/usb.c b/drivers/nfc/pn533/usb.c index 018a80674f06..efb07f944fce 100644 --- a/drivers/nfc/pn533/usb.c +++ b/drivers/nfc/pn533/usb.c @@ -476,14 +476,9 @@ static const struct pn533_phy_ops usb_phy_ops = { static int pn533_usb_probe(struct usb_interface *interface, const struct usb_device_id *id) { + struct usb_endpoint_descriptor *ep_in, *ep_out; struct pn533 *priv; struct pn533_usb_phy *phy; - struct usb_host_interface *iface_desc; - struct usb_endpoint_descriptor *endpoint; - int in_endpoint = 0; - int out_endpoint = 0; - int rc = -ENOMEM; - int i; u32 protocols; enum pn533_protocol_type protocol_type = PN533_PROTO_REQ_ACK_RESP; struct pn533_frame_ops *fops = NULL; @@ -491,6 +486,7 @@ static int pn533_usb_probe(struct usb_interface *interface, int in_buf_len = PN533_EXT_FRAME_HEADER_LEN + PN533_STD_FRAME_MAX_PAYLOAD_LEN + PN533_STD_FRAME_TAIL_LEN; + int rc; phy = devm_kzalloc(&interface->dev, sizeof(*phy), GFP_KERNEL); if (!phy) @@ -500,24 +496,14 @@ static int pn533_usb_probe(struct usb_interface *interface, if (!in_buf) return -ENOMEM; - phy->udev = usb_get_dev(interface_to_usbdev(interface)); + phy->udev = interface_to_usbdev(interface); phy->interface = interface; - iface_desc = interface->cur_altsetting; - for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { - endpoint = &iface_desc->endpoint[i].desc; - - if (!in_endpoint && usb_endpoint_is_bulk_in(endpoint)) - in_endpoint = endpoint->bEndpointAddress; - - if (!out_endpoint && usb_endpoint_is_bulk_out(endpoint)) - out_endpoint = endpoint->bEndpointAddress; - } - - if (!in_endpoint || !out_endpoint) { + rc = usb_find_common_endpoints(interface->cur_altsetting, &ep_in, + &ep_out, NULL, NULL); + if (rc) { nfc_err(&interface->dev, "Could not find bulk-in or bulk-out endpoint\n"); - rc = -ENODEV; goto error; } @@ -525,18 +511,20 @@ static int pn533_usb_probe(struct usb_interface *interface, phy->out_urb = usb_alloc_urb(0, GFP_KERNEL); phy->ack_urb = usb_alloc_urb(0, GFP_KERNEL); - if (!phy->in_urb || !phy->out_urb || !phy->ack_urb) + if (!phy->in_urb || !phy->out_urb || !phy->ack_urb) { + rc = -ENOMEM; goto error; + } usb_fill_bulk_urb(phy->in_urb, phy->udev, - usb_rcvbulkpipe(phy->udev, in_endpoint), + usb_rcvbulkpipe(phy->udev, usb_endpoint_num(ep_in)), in_buf, in_buf_len, NULL, phy); usb_fill_bulk_urb(phy->out_urb, phy->udev, - usb_sndbulkpipe(phy->udev, out_endpoint), + usb_sndbulkpipe(phy->udev, usb_endpoint_num(ep_out)), NULL, 0, pn533_out_complete, phy); usb_fill_bulk_urb(phy->ack_urb, phy->udev, - usb_sndbulkpipe(phy->udev, out_endpoint), + usb_sndbulkpipe(phy->udev, usb_endpoint_num(ep_out)), NULL, 0, pn533_ack_complete, phy); switch (id->driver_info) { @@ -600,7 +588,6 @@ error: usb_free_urb(phy->in_urb); usb_free_urb(phy->out_urb); usb_free_urb(phy->ack_urb); - usb_put_dev(phy->udev); kfree(in_buf); kfree(phy->ack_buffer); diff --git a/drivers/nfc/pn544/i2c.c b/drivers/nfc/pn544/i2c.c index a0dfb3f98d5a..b31b5bef7187 100644 --- a/drivers/nfc/pn544/i2c.c +++ b/drivers/nfc/pn544/i2c.c @@ -526,7 +526,7 @@ static int pn544_hci_i2c_fw_download(void *phy_id, const char *firmware_name, pr_info("Starting Firmware Download (%s)\n", firmware_name); - strcpy(phy->firmware_name, firmware_name); + strscpy(phy->firmware_name, firmware_name); phy->hw_variant = hw_variant; phy->fw_work_state = FW_WORK_STATE_START; diff --git a/drivers/nfc/pn544/pn544.c b/drivers/nfc/pn544/pn544.c index 32a61a185142..9d0a16ac465e 100644 --- a/drivers/nfc/pn544/pn544.c +++ b/drivers/nfc/pn544/pn544.c @@ -910,7 +910,7 @@ int pn544_hci_probe(void *phy_id, const struct nfc_phy_ops *phy_ops, struct nfc_hci_init_data init_data; int r; - info = kzalloc(sizeof(struct pn544_hci_info), GFP_KERNEL); + info = kzalloc_obj(struct pn544_hci_info); if (!info) { r = -ENOMEM; goto err_info_alloc; diff --git a/drivers/nfc/port100.c b/drivers/nfc/port100.c index 00d8ea6dcb5d..5ae61d7ebcfe 100644 --- a/drivers/nfc/port100.c +++ b/drivers/nfc/port100.c @@ -859,7 +859,7 @@ static int port100_send_cmd_async(struct port100 *dev, u8 cmd_code, if (!resp) return -ENOMEM; - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); + cmd = kzalloc_obj(*cmd); if (!cmd) { dev_kfree_skb(resp); return -ENOMEM; @@ -1211,7 +1211,7 @@ static int port100_in_send_cmd(struct nfc_digital_dev *ddev, struct port100_cb_arg *cb_arg; __le16 timeout; - cb_arg = kzalloc(sizeof(struct port100_cb_arg), GFP_KERNEL); + cb_arg = kzalloc_obj(struct port100_cb_arg); if (!cb_arg) return -ENOMEM; @@ -1377,7 +1377,7 @@ static int port100_tg_send_cmd(struct nfc_digital_dev *ddev, struct port100_tg_comm_rf_cmd *hdr; struct port100_cb_arg *cb_arg; - cb_arg = kzalloc(sizeof(struct port100_cb_arg), GFP_KERNEL); + cb_arg = kzalloc_obj(struct port100_cb_arg); if (!cb_arg) return -ENOMEM; @@ -1418,7 +1418,7 @@ static int port100_listen_mdaa(struct nfc_digital_dev *ddev, if (rc) return rc; - cb_arg = kzalloc(sizeof(struct port100_cb_arg), GFP_KERNEL); + cb_arg = kzalloc_obj(struct port100_cb_arg); if (!cb_arg) return -ENOMEM; @@ -1489,41 +1489,26 @@ MODULE_DEVICE_TABLE(usb, port100_table); static int port100_probe(struct usb_interface *interface, const struct usb_device_id *id) { + struct usb_endpoint_descriptor *ep_in, *ep_out; struct port100 *dev; int rc; - struct usb_host_interface *iface_desc; - struct usb_endpoint_descriptor *endpoint; - int in_endpoint; - int out_endpoint; u16 fw_version; u64 cmd_type_mask; - int i; dev = devm_kzalloc(&interface->dev, sizeof(struct port100), GFP_KERNEL); if (!dev) return -ENOMEM; mutex_init(&dev->out_urb_lock); - dev->udev = usb_get_dev(interface_to_usbdev(interface)); + dev->udev = interface_to_usbdev(interface); dev->interface = interface; usb_set_intfdata(interface, dev); - in_endpoint = out_endpoint = 0; - iface_desc = interface->cur_altsetting; - for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { - endpoint = &iface_desc->endpoint[i].desc; - - if (!in_endpoint && usb_endpoint_is_bulk_in(endpoint)) - in_endpoint = endpoint->bEndpointAddress; - - if (!out_endpoint && usb_endpoint_is_bulk_out(endpoint)) - out_endpoint = endpoint->bEndpointAddress; - } - - if (!in_endpoint || !out_endpoint) { + rc = usb_find_common_endpoints(interface->cur_altsetting, &ep_in, + &ep_out, NULL, NULL); + if (rc) { nfc_err(&interface->dev, "Could not find bulk-in or bulk-out endpoint\n"); - rc = -ENODEV; goto error; } @@ -1537,10 +1522,10 @@ static int port100_probe(struct usb_interface *interface, } usb_fill_bulk_urb(dev->in_urb, dev->udev, - usb_rcvbulkpipe(dev->udev, in_endpoint), + usb_rcvbulkpipe(dev->udev, usb_endpoint_num(ep_in)), NULL, 0, NULL, dev); usb_fill_bulk_urb(dev->out_urb, dev->udev, - usb_sndbulkpipe(dev->udev, out_endpoint), + usb_sndbulkpipe(dev->udev, usb_endpoint_num(ep_out)), NULL, 0, port100_send_complete, dev); dev->out_urb->transfer_flags = URB_ZERO_PACKET; @@ -1616,7 +1601,6 @@ error: usb_free_urb(dev->in_urb); usb_kill_urb(dev->out_urb); usb_free_urb(dev->out_urb); - usb_put_dev(dev->udev); return rc; } @@ -1636,7 +1620,6 @@ static void port100_disconnect(struct usb_interface *interface) usb_free_urb(dev->in_urb); usb_free_urb(dev->out_urb); - usb_put_dev(dev->udev); kfree(dev->cmd); diff --git a/drivers/nfc/s3fwrn5/firmware.c b/drivers/nfc/s3fwrn5/firmware.c index 64d61b2a715a..9145deec7f6c 100644 --- a/drivers/nfc/s3fwrn5/firmware.c +++ b/drivers/nfc/s3fwrn5/firmware.c @@ -454,7 +454,7 @@ void s3fwrn5_fw_init(struct s3fwrn5_fw_info *fw_info, const char *fw_name) fw_info->parity = 0x00; fw_info->rsp = NULL; fw_info->fw.fw = NULL; - strcpy(fw_info->fw_name, fw_name); + strscpy(fw_info->fw_name, fw_name); init_completion(&fw_info->completion); } diff --git a/drivers/nfc/s3fwrn5/i2c.c b/drivers/nfc/s3fwrn5/i2c.c index 110d086cfe5b..91b8d1445efd 100644 --- a/drivers/nfc/s3fwrn5/i2c.c +++ b/drivers/nfc/s3fwrn5/i2c.c @@ -8,10 +8,8 @@ #include <linux/clk.h> #include <linux/i2c.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/delay.h> -#include <linux/of_gpio.h> -#include <linux/of_irq.h> #include <linux/module.h> #include <net/nfc/nfc.h> @@ -146,37 +144,6 @@ out: return IRQ_HANDLED; } -static int s3fwrn5_i2c_parse_dt(struct i2c_client *client) -{ - struct s3fwrn5_i2c_phy *phy = i2c_get_clientdata(client); - struct device_node *np = client->dev.of_node; - - if (!np) - return -ENODEV; - - phy->common.gpio_en = of_get_named_gpio(np, "en-gpios", 0); - if (!gpio_is_valid(phy->common.gpio_en)) { - /* Support also deprecated property */ - phy->common.gpio_en = of_get_named_gpio(np, - "s3fwrn5,en-gpios", - 0); - if (!gpio_is_valid(phy->common.gpio_en)) - return -ENODEV; - } - - phy->common.gpio_fw_wake = of_get_named_gpio(np, "wake-gpios", 0); - if (!gpio_is_valid(phy->common.gpio_fw_wake)) { - /* Support also deprecated property */ - phy->common.gpio_fw_wake = of_get_named_gpio(np, - "s3fwrn5,fw-gpios", - 0); - if (!gpio_is_valid(phy->common.gpio_fw_wake)) - return -ENODEV; - } - - return 0; -} - static int s3fwrn5_i2c_probe(struct i2c_client *client) { struct s3fwrn5_i2c_phy *phy; @@ -193,20 +160,13 @@ static int s3fwrn5_i2c_probe(struct i2c_client *client) phy->i2c_dev = client; i2c_set_clientdata(client, phy); - ret = s3fwrn5_i2c_parse_dt(client); - if (ret < 0) - return ret; - - ret = devm_gpio_request_one(&phy->i2c_dev->dev, phy->common.gpio_en, - GPIOF_OUT_INIT_HIGH, "s3fwrn5_en"); - if (ret < 0) - return ret; + phy->common.gpio_en = devm_gpiod_get(&client->dev, "en", GPIOD_OUT_HIGH); + if (IS_ERR(phy->common.gpio_en)) + return PTR_ERR(phy->common.gpio_en); - ret = devm_gpio_request_one(&phy->i2c_dev->dev, - phy->common.gpio_fw_wake, - GPIOF_OUT_INIT_LOW, "s3fwrn5_fw_wake"); - if (ret < 0) - return ret; + phy->common.gpio_fw_wake = devm_gpiod_get(&client->dev, "wake", GPIOD_OUT_LOW); + if (IS_ERR(phy->common.gpio_fw_wake)) + return PTR_ERR(phy->common.gpio_fw_wake); /* * S3FWRN5 depends on a clock input ("XI" pin) to function properly. diff --git a/drivers/nfc/s3fwrn5/phy_common.c b/drivers/nfc/s3fwrn5/phy_common.c index deb2c039f0fd..39a60e34136c 100644 --- a/drivers/nfc/s3fwrn5/phy_common.c +++ b/drivers/nfc/s3fwrn5/phy_common.c @@ -8,7 +8,6 @@ * Bongsu Jeon <bongsu.jeon@samsung.com> */ -#include <linux/gpio.h> #include <linux/delay.h> #include <linux/module.h> @@ -19,7 +18,7 @@ void s3fwrn5_phy_set_wake(void *phy_id, bool wake) struct phy_common *phy = phy_id; mutex_lock(&phy->mutex); - gpio_set_value(phy->gpio_fw_wake, wake); + gpiod_set_value(phy->gpio_fw_wake, wake); if (wake) msleep(S3FWRN5_EN_WAIT_TIME); mutex_unlock(&phy->mutex); @@ -33,14 +32,14 @@ bool s3fwrn5_phy_power_ctrl(struct phy_common *phy, enum s3fwrn5_mode mode) phy->mode = mode; - gpio_set_value(phy->gpio_en, 1); - gpio_set_value(phy->gpio_fw_wake, 0); + gpiod_set_value(phy->gpio_en, 1); + gpiod_set_value(phy->gpio_fw_wake, 0); if (mode == S3FWRN5_MODE_FW) - gpio_set_value(phy->gpio_fw_wake, 1); + gpiod_set_value(phy->gpio_fw_wake, 1); if (mode != S3FWRN5_MODE_COLD) { msleep(S3FWRN5_EN_WAIT_TIME); - gpio_set_value(phy->gpio_en, 0); + gpiod_set_value(phy->gpio_en, 0); msleep(S3FWRN5_EN_WAIT_TIME); } diff --git a/drivers/nfc/s3fwrn5/phy_common.h b/drivers/nfc/s3fwrn5/phy_common.h index 9cef25436bf9..871bec53dd0a 100644 --- a/drivers/nfc/s3fwrn5/phy_common.h +++ b/drivers/nfc/s3fwrn5/phy_common.h @@ -12,6 +12,7 @@ #define __NFC_S3FWRN5_PHY_COMMON_H #include <linux/mutex.h> +#include <linux/gpio/consumer.h> #include <net/nfc/nci_core.h> #include "s3fwrn5.h" @@ -21,8 +22,8 @@ struct phy_common { struct nci_dev *ndev; - int gpio_en; - int gpio_fw_wake; + struct gpio_desc *gpio_en; + struct gpio_desc *gpi |
