1. 16 6月, 2017 4 次提交
    • J
      networking: add and use skb_put_u8() · 634fef61
      Johannes Berg 提交于
      Joe and Bjørn suggested that it'd be nicer to not have the
      cast in the fairly common case of doing
      	*(u8 *)skb_put(skb, 1) = c;
      
      Add skb_put_u8() for this case, and use it across the code,
      using the following spatch:
      
          @@
          expression SKB, C, S;
          typedef u8;
          identifier fn = {skb_put};
          fresh identifier fn2 = fn ## "_u8";
          @@
          - *(u8 *)fn(SKB, S) = C;
          + fn2(SKB, C);
      
      Note that due to the "S", the spatch isn't perfect, it should
      have checked that S is 1, but there's also places that use a
      sizeof expression like sizeof(var) or sizeof(u8) etc. Turns
      out that nobody ever did something like
      	*(u8 *)skb_put(skb, 2) = c;
      
      which would be wrong anyway since the second byte wouldn't be
      initialized.
      Suggested-by: NJoe Perches <joe@perches.com>
      Suggested-by: NBjørn Mork <bjorn@mork.no>
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      634fef61
    • J
      networking: make skb_push & __skb_push return void pointers · d58ff351
      Johannes Berg 提交于
      It seems like a historic accident that these return unsigned char *,
      and in many places that means casts are required, more often than not.
      
      Make these functions return void * and remove all the casts across
      the tree, adding a (u8 *) cast only where the unsigned char pointer
      was used directly, all done with the following spatch:
      
          @@
          expression SKB, LEN;
          typedef u8;
          identifier fn = { skb_push, __skb_push, skb_push_rcsum };
          @@
          - *(fn(SKB, LEN))
          + *(u8 *)fn(SKB, LEN)
      
          @@
          expression E, SKB, LEN;
          identifier fn = { skb_push, __skb_push, skb_push_rcsum };
          type T;
          @@
          - E = ((T *)(fn(SKB, LEN)))
          + E = fn(SKB, LEN)
      
          @@
          expression SKB, LEN;
          identifier fn = { skb_push, __skb_push, skb_push_rcsum };
          @@
          - fn(SKB, LEN)[0]
          + *(u8 *)fn(SKB, LEN)
      
      Note that the last part there converts from push(...)[0] to the
      more idiomatic *(u8 *)push(...).
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      d58ff351
    • J
      networking: make skb_put & friends return void pointers · 4df864c1
      Johannes Berg 提交于
      It seems like a historic accident that these return unsigned char *,
      and in many places that means casts are required, more often than not.
      
      Make these functions (skb_put, __skb_put and pskb_put) return void *
      and remove all the casts across the tree, adding a (u8 *) cast only
      where the unsigned char pointer was used directly, all done with the
      following spatch:
      
          @@
          expression SKB, LEN;
          typedef u8;
          identifier fn = { skb_put, __skb_put };
          @@
          - *(fn(SKB, LEN))
          + *(u8 *)fn(SKB, LEN)
      
          @@
          expression E, SKB, LEN;
          identifier fn = { skb_put, __skb_put };
          type T;
          @@
          - E = ((T *)(fn(SKB, LEN)))
          + E = fn(SKB, LEN)
      
      which actually doesn't cover pskb_put since there are only three
      users overall.
      
      A handful of stragglers were converted manually, notably a macro in
      drivers/isdn/i4l/isdn_bsdcomp.c and, oddly enough, one of the many
      instances in net/bluetooth/hci_sock.c. In the former file, I also
      had to fix one whitespace problem spatch introduced.
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      4df864c1
    • J
      networking: introduce and use skb_put_data() · 59ae1d12
      Johannes Berg 提交于
      A common pattern with skb_put() is to just want to memcpy()
      some data into the new space, introduce skb_put_data() for
      this.
      
      An spatch similar to the one for skb_put_zero() converts many
      of the places using it:
      
          @@
          identifier p, p2;
          expression len, skb, data;
          type t, t2;
          @@
          (
          -p = skb_put(skb, len);
          +p = skb_put_data(skb, data, len);
          |
          -p = (t)skb_put(skb, len);
          +p = skb_put_data(skb, data, len);
          )
          (
          p2 = (t2)p;
          -memcpy(p2, data, len);
          |
          -memcpy(p, data, len);
          )
      
          @@
          type t, t2;
          identifier p, p2;
          expression skb, data;
          @@
          t *p;
          ...
          (
          -p = skb_put(skb, sizeof(t));
          +p = skb_put_data(skb, data, sizeof(t));
          |
          -p = (t *)skb_put(skb, sizeof(t));
          +p = skb_put_data(skb, data, sizeof(t));
          )
          (
          p2 = (t2)p;
          -memcpy(p2, data, sizeof(*p));
          |
          -memcpy(p, data, sizeof(*p));
          )
      
          @@
          expression skb, len, data;
          @@
          -memcpy(skb_put(skb, len), data, len);
          +skb_put_data(skb, data, len);
      
      (again, manually post-processed to retain some comments)
      Reviewed-by: NStephen Hemminger <stephen@networkplumber.org>
      Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      59ae1d12
  2. 14 6月, 2017 1 次提交
  3. 02 4月, 2017 2 次提交
    • A
      NFC: pn533: change order operations in dev registation · 32ecc75d
      Andrey Rusalin 提交于
      Sometimes during probing and registration of pn533_i2c
      NULL pointer dereference happens.
      Reproduced in cycle of inserting and removing pn533_i2c
      and pn533 modules.
      
      Backtrace:
      [<8004205c>] (__queue_work) from [<80042324>] (queue_work_on+0x50/0x5c)
      r10:acdc7c80 r9:8006b330 r8:ac0dfb40 r7:ac50c600 r6:00000004 r5:acbbee40 r4:600f0113
      [<800422d4>] (queue_work_on) from [<7f7d5b6c>] (pn533_recv_frame+0x158/0x1fc [pn533])
      r7:ffffff87 r6:00000000 r5:acbbee40 r4:acbbee00
      [<7f7d5a14>] (pn533_recv_frame [pn533]) from [<7f7df4b8>] (pn533_i2c_irq_thread_fn+0x184/0x)
      r6:acb2a000 r5:00000000 r4:acdc7b90
      [<7f7df334>] (pn533_i2c_irq_thread_fn [pn533_i2c]) from [<8006b354>] (irq_thread_fn+0x24/0x)
      r7:00000000 r6:accde000 r5:ac0dfb40 r4:acdc7c80
      ...
      
      Seems there is some race condition due registration of
      irq handler until all data stuctures that could be needed
      are ready. So I re-ordered some ops. After this, problem has gone.
      
      Changes in USB part was not tested, but it should not break
      anything.
      Signed-off-by: NAndrey Rusalin <arusalin@dev.rtsoft.ru>
      Signed-off-by: NSamuel Ortiz <sameo@linux.intel.com>
      32ecc75d
    • A
      NFC: pn533: improve cmd queue handling · 5dd9c1bd
      Andrey Rusalin 提交于
      Make sure cmd is set before a frame is passed to the transport layer for
      sending. In addition pn533_send_async_complete checks if cmd is set before
      accessing its members.
      Signed-off-by: NMichael Thalmeier <michael.thalmeier@hale.at>
      
      Rework a little bit changes in pn532_send_async_complete.
      Signed-off-by: NAndrey Rusalin <arusalin@dev.rtsoft.ru>
      Signed-off-by: NSamuel Ortiz <sameo@linux.intel.com>
      5dd9c1bd
  4. 28 2月, 2017 1 次提交
  5. 10 5月, 2016 3 次提交
  6. 10 4月, 2016 4 次提交
    • M
      NFC: pn533: add I2C phy driver · dd7bedcd
      Michael Thalmeier 提交于
      This adds the I2C phy interface for the pn533 driver.
      This way the driver can be used to interact with I2C
      connected pn532 devices.
      Signed-off-by: NMichael Thalmeier <michael.thalmeier@hale.at>
      Signed-off-by: NSamuel Ortiz <sameo@linux.intel.com>
      dd7bedcd
    • M
      NFC: pn533: Separate physical layer from the core implementation · 9815c7cf
      Michael Thalmeier 提交于
      The driver now has all core stuff isolated in one file, and all
      the hardware link specifics in another. Writing a pn533 driver
      on top of another hardware link is now just a matter of adding a
      new file for that new hardware specifics.
      
      The first user of this separation will be the i2c based pn532
      driver that reuses pn533 core implementation on top of an i2c
      layer.
      Signed-off-by: NMichael Thalmeier <michael.thalmeier@hale.at>
      Signed-off-by: NSamuel Ortiz <sameo@linux.intel.com>
      9815c7cf
    • M
      NFC: pn533: Fix socket deadlock · 37f895d7
      Michael Thalmeier 提交于
      A deadlock can occur when the NFC raw socket is closed while
      the driver is processing a command.
      
      Following is the call graph of the affected situation:
      
      send data via raw_sock:
      -------------
      rawsock_tx_work
        sock_hold => socket refcnt++
        nfc_data_exchange => cb = rawsock_data_exchange_complete
      
          ops->im_transceive = pn533_transceive => arg->cb = db
                                     = rawsock_data_exchange_complete
      
            pn533_send_data_async => cb = pn533_data_exchange_complete
      
              __pn533_send_async => cmd->complete_cb = cb
                                    = pn533_data_exchange_complete
      
                if_ops->send_frame_async
      
      response:
      --------
      pn533_recv_response
        queue_work(priv->wq, &priv->cmd_complete_work)
      
      pn533_wq_cmd_complete
      
        pn533_send_async_complete
      
          cmd->complete_cb() = pn533_data_exchange_complete()
      
            arg->cb() = rawsock_data_exchange_complete()
      
              sock_put => socket refcnt-- => If the corresponding
                          socket gets closed in the meantime socket
                          will be destructed
      
                sk_free
      
                  __sk_free
      
                    sk->sk_destruct = rawsock_destruct
      
                      nfc_deactivate_target
      
                        ops->deactivate_target = pn533_deactivate_target
      
                          pn533_send_cmd_sync
      
                            pn533_send_cmd_async
      
                              __pn533_send_async
      
                                list_add_tail(&cmd->queue,&dev->cmd_queue)
                                        => add to command list because
                                           a command is currently
                                           processed
      
                              wait_for_completion
                                         => the workqueue thread waits
                                            here because it is the one
                                            processing the commands
                                               => deadlock
      
      To fix the deadlock pn533_deactivate_target is changed to
      issue the PN533_CMD_IN_RELEASE command in async mode. This
      way nothing blocks and the release command is executed after
      the current command.
      Signed-off-by: NMichael Thalmeier <michael.thalmeier@hale.at>
      Signed-off-by: NSamuel Ortiz <sameo@linux.intel.com>
      37f895d7
    • M
      NFC: pn533: Send ATR_REQ only if NFC_PROTO_NFC_DEP bit is set · e997ebbe
      Michael Thalmeier 提交于
      Currently it is not possible to only poll for passive targets
      with the pn533 driver. To change this ATR_REQ is only sent when
      NFC_PROTO_NFC_DEP is explicitly requested in poll_protocols.
      As most implementations (e.g. neard) poll for all protocols
      that are reported to be supported by the adapter, this should
      not have much of an effect on current implementations.
      Signed-off-by: NMichael Thalmeier <michael.thalmeier@hale.at>
      Signed-off-by: NSamuel Ortiz <sameo@linux.intel.com>
      e997ebbe
  7. 27 10月, 2015 1 次提交
  8. 07 4月, 2015 1 次提交
  9. 06 4月, 2015 1 次提交
  10. 24 2月, 2014 1 次提交
  11. 04 1月, 2014 1 次提交
  12. 11 12月, 2013 1 次提交
  13. 25 9月, 2013 9 次提交
  14. 14 8月, 2013 10 次提交