1. 01 3月, 2022 4 次提交
  2. 28 2月, 2022 5 次提交
    • A
      net: ipa: fix a build dependency · caef14b7
      Alex Elder 提交于
      An IPA build problem arose in the linux-next tree the other day.
      The problem is that a recent commit adds a new dependency on some
      code, and the Kconfig file for IPA doesn't reflect that dependency.
      As a result, some configurations can fail to build (particularly
      when COMPILE_TEST is enabled).
      
      The recent patch adds calls to qmp_get(), qmp_put(), and qmp_send(),
      and those are built based on the QCOM_AOSS_QMP config option.  If
      that symbol is not defined, stubs are defined, so we just need to
      ensure QCOM_AOSS_QMP is compatible with QCOM_IPA, or it's not
      defined.
      Reported-by: NRandy Dunlap <rdunlap@infradead.org>
      Fixes: 34a08176 ("net: ipa: request IPA register values be retained")
      Signed-off-by: NAlex Elder <elder@linaro.org>
      Tested-by: NRandy Dunlap <rdunlap@infradead.org>
      Acked-by: NRandy Dunlap <rdunlap@infradead.org>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      caef14b7
    • J
      atm: firestream: check the return value of ioremap() in fs_init() · d4e26aae
      Jia-Ju Bai 提交于
      The function ioremap() in fs_init() can fail, so its return value should
      be checked.
      Reported-by: NTOTE Robot <oslab@tsinghua.edu.cn>
      Signed-off-by: NJia-Ju Bai <baijiaju1990@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      d4e26aae
    • C
      net: sparx5: Add #include to remove warning · 90d40252
      Casper Andersson 提交于
      main.h uses NUM_TARGETS from main_regs.h, but
      the missing include never causes any errors
      because everywhere main.h is (currently)
      included, main_regs.h is included before.
      But since it is dependent on main_regs.h
      it should always be included.
      Signed-off-by: NCasper Andersson <casper.casan@gmail.com>
      Reviewed-by: NJoacim Zetterling <joacim.zetterling@westermo.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      90d40252
    • T
      net/smc: Fix cleanup when register ULP fails · 4d08b7b5
      Tony Lu 提交于
      This patch calls smc_ib_unregister_client() when tcp_register_ulp()
      fails, and make sure to clean it up.
      
      Fixes: d7cd421d ("net/smc: Introduce TCP ULP support")
      Signed-off-by: NTony Lu <tonylu@linux.alibaba.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      4d08b7b5
    • J
      net: ipv6: ensure we call ipv6_mc_down() at most once · 9995b408
      j.nixdorf@avm.de 提交于
      There are two reasons for addrconf_notify() to be called with NETDEV_DOWN:
      either the network device is actually going down, or IPv6 was disabled
      on the interface.
      
      If either of them stays down while the other is toggled, we repeatedly
      call the code for NETDEV_DOWN, including ipv6_mc_down(), while never
      calling the corresponding ipv6_mc_up() in between. This will cause a
      new entry in idev->mc_tomb to be allocated for each multicast group
      the interface is subscribed to, which in turn leaks one struct ifmcaddr6
      per nontrivial multicast group the interface is subscribed to.
      
      The following reproducer will leak at least $n objects:
      
      ip addr add ff2e::4242/32 dev eth0 autojoin
      sysctl -w net.ipv6.conf.eth0.disable_ipv6=1
      for i in $(seq 1 $n); do
      	ip link set up eth0; ip link set down eth0
      done
      
      Joining groups with IPV6_ADD_MEMBERSHIP (unprivileged) or setting the
      sysctl net.ipv6.conf.eth0.forwarding to 1 (=> subscribing to ff02::2)
      can also be used to create a nontrivial idev->mc_list, which will the
      leak objects with the right up-down-sequence.
      
      Based on both sources for NETDEV_DOWN events the interface IPv6 state
      should be considered:
      
       - not ready if the network interface is not ready OR IPv6 is disabled
         for it
       - ready if the network interface is ready AND IPv6 is enabled for it
      
      The functions ipv6_mc_up() and ipv6_down() should only be run when this
      state changes.
      
      Implement this by remembering when the IPv6 state is ready, and only
      run ipv6_mc_down() if it actually changed from ready to not ready.
      
      The other direction (not ready -> ready) already works correctly, as:
      
       - the interface notification triggered codepath for NETDEV_UP /
         NETDEV_CHANGE returns early if ipv6 is disabled, and
       - the disable_ipv6=0 triggered codepath skips fully initializing the
         interface as long as addrconf_link_ready(dev) returns false
       - calling ipv6_mc_up() repeatedly does not leak anything
      
      Fixes: 3ce62a84 ("ipv6: exit early in addrconf_notify() if IPv6 is disabled")
      Signed-off-by: NJohannes Nixdorf <j.nixdorf@avm.de>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      9995b408
  3. 26 2月, 2022 13 次提交
  4. 25 2月, 2022 18 次提交
    • C
      net: sparx5: Fix add vlan when invalid operation · b3a34dc3
      Casper Andersson 提交于
      Check if operation is valid before changing any
      settings in hardware. Otherwise it results in
      changes being made despite it not being a valid
      operation.
      
      Fixes: 78eab33b ("net: sparx5: add vlan support")
      Signed-off-by: NCasper Andersson <casper.casan@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      b3a34dc3
    • J
      net: chelsio: cxgb3: check the return value of pci_find_capability() · 767b9825
      Jia-Ju Bai 提交于
      The function pci_find_capability() in t3_prep_adapter() can fail, so its
      return value should be checked.
      
      Fixes: 4d22de3e ("Add support for the latest 1G/10G Chelsio adapter, T3")
      Reported-by: NTOTE Robot <oslab@tsinghua.edu.cn>
      Signed-off-by: NJia-Ju Bai <baijiaju1990@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      767b9825
    • D
      Merge branch 'ibmvnic-fixes' · 5a83dd14
      David S. Miller 提交于
      Sukadev Bhattiprolu says:
      
      ====================
      ibmvnic: Fix a race in ibmvnic_probe()
      
      If we get a transport (reset) event right after a successful CRQ_INIT
      during ibmvnic_probe() but before we set the adapter state to VNIC_PROBED,
      we will throw away the reset assuming that the adapter is still in the
      probing state. But since the adapter has completed the CRQ_INIT any
      subsequent CRQs the we send will be ignored by the vnicserver until
      we release/init the CRQ again. This can leave the adapter unconfigured.
      
      While here fix a couple of other bugs that were observed (Patches 1,2,4).
      ====================
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      5a83dd14
    • S
      ibmvnic: Allow queueing resets during probe · fd98693c
      Sukadev Bhattiprolu 提交于
      We currently don't allow queuing resets when adapter is in VNIC_PROBING
      state - instead we throw away the reset and return EBUSY. The reasoning
      is probably that during ibmvnic_probe() the ibmvnic_adapter itself is
      being initialized so performing a reset during this time can lead us to
      accessing fields in the ibmvnic_adapter that are not fully initialized.
      A review of the code shows that all the adapter state neede to process a
      reset is initialized before registering the CRQ so that should no longer
      be a concern.
      
      Further the expectation is that if we do get a reset (transport event)
      during probe, the do..while() loop in ibmvnic_probe() will handle this
      by reinitializing the CRQ.
      
      While that is true to some extent, it is possible that the reset might
      occur _after_ the CRQ is registered and CRQ_INIT message was exchanged
      but _before_ the adapter state is set to VNIC_PROBED. As mentioned above,
      such a reset will be thrown away. While the client assumes that the
      adapter is functional, the vnic server will wait for the client to reinit
      the adapter. This disconnect between the two leaves the adapter down
      needing manual intervention.
      
      Because ibmvnic_probe() has other work to do after initializing the CRQ
      (such as registering the netdev at a minimum) and because the reset event
      can occur at any instant after the CRQ is initialized, there will always
      be a window between initializing the CRQ and considering the adapter
      ready for resets (ie state == PROBED).
      
      So rather than discarding resets during this window, allow queueing them
      - but only process them after the adapter is fully initialized.
      
      To do this, introduce a new completion state ->probe_done and have the
      reset worker thread wait on this before processing resets.
      
      This change brings up two new situations in or just after ibmvnic_probe().
      First after one or more resets were queued, we encounter an error and
      decide to retry the initialization.  At that point the queued resets are
      no longer relevant since we could be talking to a new vnic server. So we
      must purge/flush the queued resets before restarting the initialization.
      As a side note, since we are still in the probing stage and we have not
      registered the netdev, it will not be CHANGE_PARAM reset.
      
      Second this change opens up a potential race between the worker thread
      in __ibmvnic_reset(), the tasklet and the ibmvnic_open() due to the
      following sequence of events:
      
      	1. Register CRQ
      	2. Get transport event before CRQ_INIT completes.
      	3. Tasklet schedules reset:
      		a) add rwi to list
      		b) schedule_work() to start worker thread which runs
      		   and waits for ->probe_done.
      	4. ibmvnic_probe() decides to retry, purges rwi_list
      	5. Re-register crq and this time rest of probe succeeds - register
      	   netdev and complete(->probe_done).
      	6. Worker thread resumes in __ibmvnic_reset() from 3b.
      	7. Worker thread sets ->resetting bit
      	8. ibmvnic_open() comes in, notices ->resetting bit, sets state
      	   to IBMVNIC_OPEN and returns early expecting worker thread to
      	   finish the open.
      	9. Worker thread finds rwi_list empty and returns without
      	   opening the interface.
      
      If this happens, the ->ndo_open() call is effectively lost and the
      interface remains down. To address this, ensure that ->rwi_list is
      not empty before setting the ->resetting  bit. See also comments in
      __ibmvnic_reset().
      
      Fixes: 6a2fb0e9 ("ibmvnic: driver initialization for kdump/kexec")
      Signed-off-by: NSukadev Bhattiprolu <sukadev@linux.ibm.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      fd98693c
    • S
      ibmvnic: clear fop when retrying probe · f628ad53
      Sukadev Bhattiprolu 提交于
      Clear ->failover_pending flag that may have been set in the previous
      pass of registering CRQ. If we don't clear, a subsequent ibmvnic_open()
      call would be misled into thinking a failover is pending and assuming
      that the reset worker thread would open the adapter. If this pass of
      registering the CRQ succeeds (i.e there is no transport event), there
      wouldn't be a reset worker thread.
      
      This would leave the adapter unconfigured and require manual intervention
      to bring it up during boot.
      
      Fixes: 5a18e1e0 ("ibmvnic: Fix failover case for non-redundant configuration")
      Signed-off-by: NSukadev Bhattiprolu <sukadev@linux.ibm.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      f628ad53
    • S
      ibmvnic: init init_done_rc earlier · ae16bf15
      Sukadev Bhattiprolu 提交于
      We currently initialize the ->init_done completion/return code fields
      before issuing a CRQ_INIT command. But if we get a transport event soon
      after registering the CRQ the taskslet may already have recorded the
      completion and error code. If we initialize here, we might overwrite/
      lose that and end up issuing the CRQ_INIT only to timeout later.
      
      If that timeout happens during probe, we will leave the adapter in the
      DOWN state rather than retrying to register/init the CRQ.
      
      Initialize the completion before registering the CRQ so we don't lose
      the notification.
      
      Fixes: 032c5e82 ("Driver for IBM System i/p VNIC protocol")
      Signed-off-by: NSukadev Bhattiprolu <sukadev@linux.ibm.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ae16bf15
    • S
      ibmvnic: register netdev after init of adapter · 570425f8
      Sukadev Bhattiprolu 提交于
      Finish initializing the adapter before registering netdev so state
      is consistent.
      
      Fixes: c26eba03 ("ibmvnic: Update reset infrastructure to support tunable parameters")
      Signed-off-by: NSukadev Bhattiprolu <sukadev@linux.ibm.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      570425f8
    • S
      ibmvnic: complete init_done on transport events · 36491f2d
      Sukadev Bhattiprolu 提交于
      If we get a transport event, set the error and mark the init as
      complete so the attempt to send crq-init or login fail sooner
      rather than wait for the timeout.
      
      Fixes: bbd669a8 ("ibmvnic: Fix completion structure initialization")
      Signed-off-by: NSukadev Bhattiprolu <sukadev@linux.ibm.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      36491f2d
    • S
      ibmvnic: define flush_reset_queue helper · 83da53f7
      Sukadev Bhattiprolu 提交于
      Define and use a helper to flush the reset queue.
      
      Fixes: 2770a798 ("ibmvnic: Introduce hard reset recovery")
      Signed-off-by: NSukadev Bhattiprolu <sukadev@linux.ibm.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      83da53f7
    • S
      ibmvnic: initialize rc before completing wait · 765559b1
      Sukadev Bhattiprolu 提交于
      We should initialize ->init_done_rc before calling complete(). Otherwise
      the waiting thread may see ->init_done_rc as 0 before we have updated it
      and may assume that the CRQ was successful.
      
      Fixes: 6b278c0c ("ibmvnic delay complete()")
      Signed-off-by: NSukadev Bhattiprolu <sukadev@linux.ibm.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      765559b1
    • S
      ibmvnic: free reset-work-item when flushing · 8d0657f3
      Sukadev Bhattiprolu 提交于
      Fix a tiny memory leak when flushing the reset work queue.
      
      Fixes: 2770a798 ("ibmvnic: Introduce hard reset recovery")
      Signed-off-by: NSukadev Bhattiprolu <sukadev@linux.ibm.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      8d0657f3
    • D
      Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec · 31372fe9
      David S. Miller 提交于
      Steffen Klassert says:
      
      ====================
      1) Fix PMTU for IPv6 if the reported MTU minus the ESP overhead is
         smaller than 1280. From Jiri Bohac.
      
      2) Fix xfrm interface ID and inter address family tunneling when
         migrating xfrm states. From Yan Yan.
      
      3) Add missing xfrm intrerface ID initialization on xfrmi_changelink.
         From Antony Antony.
      
      4) Enforce validity of xfrm offload input flags so that userspace can't
         send undefined flags to the offload driver.
         From Leon Romanovsky.
      ====================
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      31372fe9
    • V
      net: dcb: flush lingering app table entries for unregistered devices · 91b0383f
      Vladimir Oltean 提交于
      If I'm not mistaken (and I don't think I am), the way in which the
      dcbnl_ops work is that drivers call dcb_ieee_setapp() and this populates
      the application table with dynamically allocated struct dcb_app_type
      entries that are kept in the module-global dcb_app_list.
      
      However, nobody keeps exact track of these entries, and although
      dcb_ieee_delapp() is supposed to remove them, nobody does so when the
      interface goes away (example: driver unbinds from device). So the
      dcb_app_list will contain lingering entries with an ifindex that no
      longer matches any device in dcb_app_lookup().
      
      Reclaim the lost memory by listening for the NETDEV_UNREGISTER event and
      flushing the app table entries of interfaces that are now gone.
      
      In fact something like this used to be done as part of the initial
      commit (blamed below), but it was done in dcbnl_exit() -> dcb_flushapp(),
      essentially at module_exit time. That became dead code after commit
      7a6b6f51 ("DCB: fix kconfig option") which essentially merged
      "tristate config DCB" and "bool config DCBNL" into a single "bool config
      DCB", so net/dcb/dcbnl.c could not be built as a module anymore.
      
      Commit 36b9ad80 ("net/dcb: make dcbnl.c explicitly non-modular")
      recognized this and deleted dcbnl_exit() and dcb_flushapp() altogether,
      leaving us with the version we have today.
      
      Since flushing application table entries can and should be done as soon
      as the netdevice disappears, fundamentally the commit that is to blame
      is the one that introduced the design of this API.
      
      Fixes: 9ab933ab ("dcbnl: add appliction tlv handlers")
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      91b0383f
    • D
      net/smc: fix connection leak · 9f1c50cf
      D. Wythe 提交于
      There's a potential leak issue under following execution sequence :
      
      smc_release  				smc_connect_work
      if (sk->sk_state == SMC_INIT)
      					send_clc_confirim
      	tcp_abort();
      					...
      					sk.sk_state = SMC_ACTIVE
      smc_close_active
      switch(sk->sk_state) {
      ...
      case SMC_ACTIVE:
      	smc_close_final()
      	// then wait peer closed
      
      Unfortunately, tcp_abort() may discard CLC CONFIRM messages that are
      still in the tcp send buffer, in which case our connection token cannot
      be delivered to the server side, which means that we cannot get a
      passive close message at all. Therefore, it is impossible for the to be
      disconnected at all.
      
      This patch tries a very simple way to avoid this issue, once the state
      has changed to SMC_ACTIVE after tcp_abort(), we can actively abort the
      smc connection, considering that the state is SMC_INIT before
      tcp_abort(), abandoning the complete disconnection process should not
      cause too much problem.
      
      In fact, this problem may exist as long as the CLC CONFIRM message is
      not received by the server. Whether a timer should be added after
      smc_close_final() needs to be discussed in the future. But even so, this
      patch provides a faster release for connection in above case, it should
      also be valuable.
      
      Fixes: 39f41f36 ("net/smc: common release code for non-accepted sockets")
      Signed-off-by: ND. Wythe <alibuda@linux.alibaba.com>
      Acked-by: NKarsten Graul <kgraul@linux.ibm.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      9f1c50cf
    • V
      net: stmmac: only enable DMA interrupts when ready · 087a7b94
      Vincent Whitchurch 提交于
      In this driver's ->ndo_open() callback, it enables DMA interrupts,
      starts the DMA channels, then requests interrupts with request_irq(),
      and then finally enables napi.
      
      If RX DMA interrupts are received before napi is enabled, no processing
      is done because napi_schedule_prep() will return false.  If the network
      has a lot of broadcast/multicast traffic, then the RX ring could fill up
      completely before napi is enabled.  When this happens, no further RX
      interrupts will be delivered, and the driver will fail to receive any
      packets.
      
      Fix this by only enabling DMA interrupts after all other initialization
      is complete.
      
      Fixes: 523f11b5 ("net: stmmac: move hardware setup for stmmac_open to new function")
      Reported-by: NLars Persson <larper@axis.com>
      Signed-off-by: NVincent Whitchurch <vincent.whitchurch@axis.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      087a7b94
    • M
      xen/netfront: destroy queues before real_num_tx_queues is zeroed · dcf4ff7a
      Marek Marczykowski-Górecki 提交于
      xennet_destroy_queues() relies on info->netdev->real_num_tx_queues to
      delete queues. Since d7dac083
      ("net-sysfs: update the queue counts in the unregistration path"),
      unregister_netdev() indirectly sets real_num_tx_queues to 0. Those two
      facts together means, that xennet_destroy_queues() called from
      xennet_remove() cannot do its job, because it's called after
      unregister_netdev(). This results in kfree-ing queues that are still
      linked in napi, which ultimately crashes:
      
          BUG: kernel NULL pointer dereference, address: 0000000000000000
          #PF: supervisor read access in kernel mode
          #PF: error_code(0x0000) - not-present page
          PGD 0 P4D 0
          Oops: 0000 [#1] PREEMPT SMP PTI
          CPU: 1 PID: 52 Comm: xenwatch Tainted: G        W         5.16.10-1.32.fc32.qubes.x86_64+ #226
          RIP: 0010:free_netdev+0xa3/0x1a0
          Code: ff 48 89 df e8 2e e9 00 00 48 8b 43 50 48 8b 08 48 8d b8 a0 fe ff ff 48 8d a9 a0 fe ff ff 49 39 c4 75 26 eb 47 e8 ed c1 66 ff <48> 8b 85 60 01 00 00 48 8d 95 60 01 00 00 48 89 ef 48 2d 60 01 00
          RSP: 0000:ffffc90000bcfd00 EFLAGS: 00010286
          RAX: 0000000000000000 RBX: ffff88800edad000 RCX: 0000000000000000
          RDX: 0000000000000001 RSI: ffffc90000bcfc30 RDI: 00000000ffffffff
          RBP: fffffffffffffea0 R08: 0000000000000000 R09: 0000000000000000
          R10: 0000000000000000 R11: 0000000000000001 R12: ffff88800edad050
          R13: ffff8880065f8f88 R14: 0000000000000000 R15: ffff8880066c6680
          FS:  0000000000000000(0000) GS:ffff8880f3300000(0000) knlGS:0000000000000000
          CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
          CR2: 0000000000000000 CR3: 00000000e998c006 CR4: 00000000003706e0
          Call Trace:
           <TASK>
           xennet_remove+0x13d/0x300 [xen_netfront]
           xenbus_dev_remove+0x6d/0xf0
           __device_release_driver+0x17a/0x240
           device_release_driver+0x24/0x30
           bus_remove_device+0xd8/0x140
           device_del+0x18b/0x410
           ? _raw_spin_unlock+0x16/0x30
           ? klist_iter_exit+0x14/0x20
           ? xenbus_dev_request_and_reply+0x80/0x80
           device_unregister+0x13/0x60
           xenbus_dev_changed+0x18e/0x1f0
           xenwatch_thread+0xc0/0x1a0
           ? do_wait_intr_irq+0xa0/0xa0
           kthread+0x16b/0x190
           ? set_kthread_struct+0x40/0x40
           ret_from_fork+0x22/0x30
           </TASK>
      
      Fix this by calling xennet_destroy_queues() from xennet_uninit(),
      when real_num_tx_queues is still available. This ensures that queues are
      destroyed when real_num_tx_queues is set to 0, regardless of how
      unregister_netdev() was called.
      
      Originally reported at
      https://github.com/QubesOS/qubes-issues/issues/7257
      
      Fixes: d7dac083 ("net-sysfs: update the queue counts in the unregistration path")
      Cc: stable@vger.kernel.org
      Signed-off-by: NMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      dcf4ff7a
    • V
      can: gs_usb: change active_channels's type from atomic_t to u8 · 035b0fcf
      Vincent Mailhol 提交于
      The driver uses an atomic_t variable: gs_usb:active_channels to keep
      track of the number of opened channels in order to only allocate
      memory for the URBs when this count changes from zero to one.
      
      However, the driver does not decrement the counter when an error
      occurs in gs_can_open(). This issue is fixed by changing the type from
      atomic_t to u8 and by simplifying the logic accordingly.
      
      It is safe to use an u8 here because the network stack big kernel lock
      (a.k.a. rtnl_mutex) is being hold. For details, please refer to [1].
      
      [1] https://lore.kernel.org/linux-can/CAMZ6Rq+sHpiw34ijPsmp7vbUpDtJwvVtdV7CvRZJsLixjAFfrg@mail.gmail.com/T/#t
      
      Fixes: d08e973a ("can: gs_usb: Added support for the GS_USB CAN devices")
      Link: https://lore.kernel.org/all/20220214234814.1321599-1-mailhol.vincent@wanadoo.frSigned-off-by: NVincent Mailhol <mailhol.vincent@wanadoo.fr>
      Signed-off-by: NMarc Kleine-Budde <mkl@pengutronix.de>
      035b0fcf
    • V
      can: etas_es58x: change opened_channel_cnt's type from atomic_t to u8 · f4896248
      Vincent Mailhol 提交于
      The driver uses an atomic_t variable: struct
      es58x_device::opened_channel_cnt to keep track of the number of opened
      channels in order to only allocate memory for the URBs when this count
      changes from zero to one.
      
      While the intent was to prevent race conditions, the choice of an
      atomic_t turns out to be a bad idea for several reasons:
      
      - implementation is incorrect and fails to decrement
        opened_channel_cnt when the URB allocation fails as reported in
        [1].
      
      - even if opened_channel_cnt were to be correctly decremented,
        atomic_t is insufficient to cover edge cases: there can be a race
        condition in which 1/ a first process fails to allocate URBs
        memory 2/ a second process enters es58x_open() before the first
        process does its cleanup and decrements opened_channed_cnt. In
        which case, the second process would successfully return despite
        the URBs memory not being allocated.
      
      - actually, any kind of locking mechanism was useless here because
        it is redundant with the network stack big kernel lock
        (a.k.a. rtnl_lock) which is being hold by all the callers of
        net_device_ops:ndo_open() and net_device_ops:ndo_close(). c.f. the
        ASSERST_RTNL() calls in __dev_open() [2] and __dev_close_many()
        [3].
      
      The atmomic_t is thus replaced by a simple u8 type and the logic to
      increment and decrement es58x_device:opened_channel_cnt is simplified
      accordingly fixing the bug reported in [1]. We do not check again for
      ASSERST_RTNL() as this is already done by the callers.
      
      [1] https://lore.kernel.org/linux-can/20220201140351.GA2548@kili/T/#u
      [2] https://elixir.bootlin.com/linux/v5.16/source/net/core/dev.c#L1463
      [3] https://elixir.bootlin.com/linux/v5.16/source/net/core/dev.c#L1541
      
      Fixes: 85372578 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
      Link: https://lore.kernel.org/all/20220212112713.577957-1-mailhol.vincent@wanadoo.frReported-by: NDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: NVincent Mailhol <mailhol.vincent@wanadoo.fr>
      Signed-off-by: NMarc Kleine-Budde <mkl@pengutronix.de>
      f4896248