28 Oct, 2016

4 commits

  • Now genl_register_family() is the only thing (other than the
    users themselves, perhaps, but I didn't find any doing that)
    writing to the family struct.

    In all families that I found, genl_register_family() is only
    called from __init functions (some indirectly, in which case
    I've add __init annotations to clarifly things), so all can
    actually be marked __ro_after_init.

    This protects the data structure from accidental corruption.

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     
  • Instead of providing macros/inline functions to initialize
    the families, make all users initialize them statically and
    get rid of the macros.

    This reduces the kernel code size by about 1.6k on x86-64
    (with allyesconfig).

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     
  • Static family IDs have never really been used, the only
    use case was the workaround I introduced for those users
    that assumed their family ID was also their multicast
    group ID.

    Additionally, because static family IDs would never be
    reserved by the generic netlink code, using a relatively
    low ID would only work for built-in families that can be
    registered immediately after generic netlink is started,
    which is basically only the control family (apart from
    the workaround code, which I also had to add code for so
    it would reserve those IDs)

    Thus, anything other than GENL_ID_GENERATE is flawed and
    luckily not used except in the cases I mentioned. Move
    those workarounds into a few lines of code, and then get
    rid of GENL_ID_GENERATE entirely, making it more robust.

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     
  • This helper function allows family implementations to access
    their family's attrbuf. This gets rid of the attrbuf usage
    in families, and also adds locking validation, since it's not
    valid to use the attrbuf with parallel_ops or outside of the
    dumpit callback.

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     

30 Dec, 2015

1 commit


27 Oct, 2015

1 commit


20 Oct, 2015

1 commit

  • The exit label performs device_unlock(&dev->dev);, which will fail when dev
    is NULL, and nfc_put_device(dev);, which is not useful when dev is NULL, so
    just exit the function immediately.

    Problem found using scripts/coccinelle/null/deref_null.cocci

    Signed-off-by: Julia Lawall
    Signed-off-by: Samuel Ortiz

    Julia Lawall
     

21 Aug, 2015

1 commit

  • A proprietary vendor command may send back useful data to the user
    application.

    For example, the field level applied on the NFC router antenna.

    Still based on net/wireless/nl80211.c implementation,
    add nfc_vendor_cmd_alloc_reply_skb and nfc_vendor_cmd_reply in
    order to send back over netlink data generated by a proprietary
    command.

    Signed-off-by: Christophe Ricard
    Signed-off-by: Samuel Ortiz

    Christophe Ricard
     

17 Aug, 2015

2 commits

  • When NFC_ATTR_VENDOR_DATA is not set, data_len is 0 and data is NULL.

    Fixes the following warning:

    net/nfc/netlink.c:1536:3: warning: 'data' may be used uninitialized
    +in this function [-Wmaybe-uninitialized]
    return cmd->doit(dev, data, data_len);

    Cc: stable@vger.kernel.org
    Signed-off-by: Christophe Ricard
    Signed-off-by: Samuel Ortiz

    Christophe Ricard
     
  • NFC_ATTR_VENDOR_DATA is an optional vendor_cmd argument.
    The current code was potentially using a non existing argument
    leading to potential catastrophic results.

    Cc: stable@vger.kernel.org
    Signed-off-by: Christophe Ricard
    Signed-off-by: Samuel Ortiz

    Christophe Ricard
     

09 Jun, 2015

1 commit

  • Vendor commands are passed from userspace through the
    NFC_CMD_VENDOR netlink command, allowing driver and hardware
    specific operations implementations like for example RF tuning
    or production line calibration.

    Drivers will associate a set of vendor commands to a vendor
    id, which could typically be an OUI. The netlink kernel
    implementation will try to match the received vendor id
    and sub command attributes with the registered ones. When
    such match is found, the driver defined sub command routine
    is called.

    Signed-off-by: Samuel Ortiz

    Samuel Ortiz
     

14 Apr, 2015

1 commit


03 Feb, 2015

1 commit

  • NFC_EVT_TRANSACTION is sent through netlink in order for a
    specific application running on a secure element to notify
    userspace of an event. Typically the secure element application
    counterpart on the host could interpret that event and act
    upon it.

    Forwarded information contains:
    - SE host generating the event
    - Application IDentifier doing the operation
    - Applications parameters

    Signed-off-by: Christophe Ricard
    Signed-off-by: Samuel Ortiz

    Christophe Ricard
     

18 Jan, 2015

1 commit

  • Contrary to common expectations for an "int" return, these functions
    return only a positive value -- if used correctly they cannot even
    return 0 because the message header will necessarily be in the skb.

    This makes the very common pattern of

    if (genlmsg_end(...) < 0) { ... }

    be a whole bunch of dead code. Many places also simply do

    return nlmsg_end(...);

    and the caller is expected to deal with it.

    This also commonly (at least for me) causes errors, because it is very
    common to write

    if (my_function(...))
    /* error condition */

    and if my_function() does "return nlmsg_end()" this is of course wrong.

    Additionally, there's not a single place in the kernel that actually
    needs the message length returned, and if anyone needs it later then
    it'll be very easy to just use skb->len there.

    Remove this, and make the functions void. This removes a bunch of dead
    code as described above. The patch adds lines because I did

    - return nlmsg_end(...);
    + nlmsg_end(...);
    + return 0;

    I could have preserved all the function's return values by returning
    skb->len, but instead I've audited all the places calling the affected
    functions and found that none cared. A few places actually compared
    the return value with < 0 with no change in behaviour, so I opted for the more
    efficient version.

    One instance of the error I've made numerous times now is also present
    in net/phonet/pn_netlink.c in the route_dumpit() function - it didn't
    check for
    Signed-off-by: David S. Miller

    Johannes Berg
     

03 Dec, 2014

2 commits


17 Feb, 2014

1 commit


11 Dec, 2013

1 commit

  • Several files refer to an old address for the Free Software Foundation
    in the file header comment. Resolve by replacing the address with
    the URL so that we do not have to keep
    updating the header comments anytime the address changes.

    CC: linux-wireless@vger.kernel.org
    CC: Lauro Ramos Venancio
    CC: Aloisio Almeida Jr
    CC: Samuel Ortiz
    Signed-off-by: Jeff Kirsher
    Signed-off-by: John W. Linville

    Jeff Kirsher
     

20 Nov, 2013

3 commits

  • Register generic netlink multicast groups as an array with
    the family and give them contiguous group IDs. Then instead
    of passing the global group ID to the various functions that
    send messages, pass the ID relative to the family - for most
    families that's just 0 because the only have one group.

    This avoids the list_head and ID in each group, adding a new
    field for the mcast group ID offset to the family.

    At the same time, this allows us to prevent abusing groups
    again like the quota and dropmon code did, since we can now
    check that a family only uses a group it owns.

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     
  • This doesn't really change anything, but prepares for the
    next patch that will change the APIs to pass the group ID
    within the family, rather than the global group ID.

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     
  • As suggested by David Miller, make genl_register_family_with_ops()
    a macro and pass only the array, evaluating ARRAY_SIZE() in the
    macro, this is a little safer.

    The openvswitch has some indirection, assing ops/n_ops directly in
    that code. This might ultimately just assign the pointers in the
    family initializations, saving the struct genl_family_and_ops and
    code (once mcast groups are handled differently.)

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     

15 Nov, 2013

1 commit

  • Now that genl_ops are no longer modified in place when
    registering, they can be made const. This patch was done
    mostly with spatch:

    @@
    identifier ops;
    @@
    +const
    struct genl_ops ops[] = {
    ...
    };

    (except the struct thing in net/openvswitch/datapath.c)

    Signed-off-by: Johannes Berg
    Signed-off-by: David S. Miller

    Johannes Berg
     

07 Oct, 2013

1 commit


25 Sep, 2013

1 commit


14 Aug, 2013

2 commits


31 Jul, 2013

1 commit


14 Jun, 2013

4 commits

  • Enabling or disabling an NFC accessible secure element through netlink
    requires giving both an NFC controller and a secure element indexes.
    Once enabled the secure element will handle card emulation once polling
    starts.

    Signed-off-by: Samuel Ortiz

    Samuel Ortiz
     
  • When an NFC driver or host controller stack discovers a secure element,
    it will call nfc_add_se(). In order for userspace applications to use
    these secure elements, a netlink event will then be sent with the SE
    index and its type. With that information userspace applications can
    decide wether or not to enable SEs, through their indexes.

    Signed-off-by: Samuel Ortiz

    Samuel Ortiz
     
  • Supported secure elements are typically found during a discovery process
    initiated when the NFC controller is up and running. For a given NFC
    chipset there can be many configurations (embedded SE or not, with or
    without a SIM card wired to the NFC controller SWP interface, etc...) and
    thus driver code will never know before hand which SEs are available.
    So we remove this field, it will be replaced by a real SE discovery
    mechanism.

    Signed-off-by: Samuel Ortiz

    Samuel Ortiz
     
  • As several NFC chipsets can have their firmwares upgraded and
    reflashed, this patchset adds a new netlink command to trigger
    that the driver loads or flashes a new firmware. This will allows
    userspace triggered firmware upgrade through netlink.
    The firmware name or hint is passed as a parameter, and the driver
    will eventually fetch the firmware binary through the request_firmware
    API.
    The cmd can only be executed when the nfc dev is not in use. Actual
    firmware loading/flashing is an asynchronous operation. Result of the
    operation shall send a new event up to user space through the nfc dev
    multicast socket. During operation, the nfc dev is not openable and
    thus not usable.

    Signed-off-by: Eric Lapuyade
    Signed-off-by: Samuel Ortiz

    Eric Lapuyade
     

26 Apr, 2013

1 commit


11 Mar, 2013

2 commits


10 Jan, 2013

1 commit

  • Each NFC adapter can have several links to different secure elements and
    that property needs to be exported by the drivers.
    A secure element link can be enabled and disabled, and card emulation will
    be handled by the currently active one. Otherwise card emulation will be
    host implemented.

    Signed-off-by: Samuel Ortiz

    Samuel Ortiz
     

29 Oct, 2012

1 commit

  • NFC_CMD_LLC_GET_PARAMS: request LTO, RW, and MIUX parameters for a device

    NFC_CMD_LLC_SET_PARAMS: set one or more of LTO, RW, and MIUX parameters for
    a device. LTO must be set before the link is up otherwise -EINPROGRESS is
    returned. RW and MIUX can be set at anytime and will be passed in subsequent
    CONNECT and CC messages. If one of the passed parameters is wrong none is
    set and -EINVAL is returned.

    Signed-off-by: Thierry Escande
    Signed-off-by: Samuel Ortiz

    Thierry Escande
     

27 Oct, 2012

2 commits


28 Sep, 2012

1 commit


27 Sep, 2012

1 commit

  • netlink_register_notifier requires notify functions to not sleep.
    nfc_stop_poll locks device mutex and must not be called from notifier.
    Create workqueue that will handle this for all devices.

    BUG: sleeping function called from invalid context at kernel/mutex.c:269
    in_atomic(): 0, irqs_disabled(): 0, pid: 4497, name: neard
    1 lock held by neard/4497:
    Pid: 4497, comm: neard Not tainted 3.5.0-999-nfc+ #5
    Call Trace:
    [] __might_sleep+0x145/0x200
    [] mutex_lock_nested+0x2e/0x50
    [] nfc_stop_poll+0x39/0xb0
    [] nfc_genl_rcv_nl_event+0x77/0xc0
    [] notifier_call_chain+0x5c/0x120
    [] __atomic_notifier_call_chain+0x86/0x140
    [] ? notifier_call_chain+0x120/0x120
    [] ? skb_dequeue+0x67/0x90
    [] atomic_notifier_call_chain+0x16/0x20
    [] netlink_release+0x24a/0x280
    [] sock_release+0x28/0xa0
    [] sock_close+0x17/0x30
    [] __fput+0xcc/0x250
    [] ____fput+0xe/0x10
    [] task_work_run+0x69/0x90
    [] do_notify_resume+0x81/0xd0
    [] int_signal+0x12/0x17

    Signed-off-by: Szymon Janc
    Signed-off-by: Samuel Ortiz

    Szymon Janc