Search Linux Wireless

Re: [PATCH 1/4] NFC: Add NFC dev_up and dev_down control operations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Ilan,

On Tue, Aug 16, 2011 at 2:35 PM, Elias, Ilan <ilane@xxxxxx> wrote:
> +/**
> + * nfc_dev_down - turn off the NFC device
> + *
> + * @dev: The nfc device to be turned off
> + */
> +int nfc_dev_down(struct nfc_dev *dev)
> +{
> +       int rc = 0;
> +
> +       nfc_dbg("dev_name=%s", dev_name(&dev->dev));
> +
> +       device_lock(&dev->dev);
> +
> +       if (!device_is_registered(&dev->dev)) {
> +               rc = -ENODEV;
> +               goto error;
> +       }
> +
> +       if (!dev->dev_up) {
> +               rc = -EINVAL;
> +               goto error;
> +       }

I think -EALREADY would fit better.

> +
> +       if (dev->ops->dev_down)
> +               dev->ops->dev_down(dev);
> +
> +       dev->dev_up = false;

What happens if the driver is polling for targets or even with a
remote target activated? The nfc_dev structure has some control to
track the driver state (e.g. dev->polling) that must have their values
updated. Otherwise, the next start_poll() call would fail with EBUSY.

> +static int nfc_genl_dev_up(struct sk_buff *skb, struct genl_info *info)
> +{
> +       struct nfc_dev *dev;
> +       int rc;
> +       u32 idx;
> +
> +       nfc_dbg("entry");
> +
> +       if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
> +               return -EINVAL;
> +
> +       idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
> +
> +       dev = nfc_get_device(idx);
> +       if (!dev)
> +               return -ENODEV;
> +
> +       mutex_lock(&dev->genl_data.genl_data_mutex);
> +
> +       rc = nfc_dev_up(dev);
> +
> +       mutex_unlock(&dev->genl_data.genl_data_mutex);

This mutex is used to protect the variable dev->genl_data.poll_req_pid
in cases when the netlink socket is closed in parallel with start_poll
or stop_poll calls. As you are not accessing poll_req_pid, you don't
need to care about this mutex.

> +static int nfc_genl_dev_down(struct sk_buff *skb, struct genl_info *info)
> +{
> +       struct nfc_dev *dev;
> +       int rc;
> +       u32 idx;
> +
> +       nfc_dbg("entry");
> +
> +       if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
> +               return -EINVAL;
> +
> +       idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
> +
> +       dev = nfc_get_device(idx);
> +       if (!dev)
> +               return -ENODEV;
> +
> +       mutex_lock(&dev->genl_data.genl_data_mutex);
> +
> +       rc = nfc_dev_down(dev);
> +
> +       mutex_unlock(&dev->genl_data.genl_data_mutex);

The same as above.



Regards,
Aloisio
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux