netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Souptick Joarder <jrdr.linux@gmail.com>
To: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Cc: linux-kernel@vger.kernel.org, ltp@lists.linux.it,
	Jeroen Hofstee <jhofstee@victronenergy.com>,
	kbuild test robot <lkp@intel.com>,
	Richard Palethorpe <rpalethorpe@suse.de>,
	kernel test robot <oliver.sang@intel.com>,
	lkp@lists.01.org, Jiri Slaby <jirislaby@kernel.org>,
	Linux Memory Management List <linux-mm@kvack.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	Paolo Abeni <pabeni@redhat.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
	Wolfgang Grandegger <wg@grandegger.com>,
	linux-can@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH v3] can: slcan: do not sleep with a spin lock held
Date: Thu, 21 Jul 2022 07:28:03 +0530	[thread overview]
Message-ID: <CAFqt6zaMnfGhwxnnJrbW1eoiGy46-WNUe8H-iqztRmZW5Z8jfQ@mail.gmail.com> (raw)
In-Reply-To: <20220715072951.859586-1-dario.binacchi@amarulasolutions.com>

On Fri, Jul 15, 2022 at 1:00 PM Dario Binacchi
<dario.binacchi@amarulasolutions.com> wrote:
>
> We can't call close_candev() with a spin lock held, so release the lock
> before calling it. After calling close_candev(), we can update the
> fields of the private `struct can_priv' without having to acquire the
> lock.

But here we are updating private 'struct can_priv' before close_candev() while
taking the lock.  If we go by change logs, then spin_unlock_bh() need to called
before close_candev() and we can update the private 'struct can_priv'
in existing place.

>
> Fixes: c4e54b063f42f ("can: slcan: use CAN network device driver API")
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Link: https://lore.kernel.org/linux-kernel/Ysrf1Yc5DaRGN1WE@xsang-OptiPlex-9020/
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
>
> ---
>
> Changes in v3:
> - Update the commit message.
> - Reset sl->rcount and sl->xleft before releasing the spin lock.
>
> Changes in v2:
> - Release the lock just before calling the close_candev().
>
>  drivers/net/can/slcan/slcan-core.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c
> index 54d29a410ad5..d40ddc596596 100644
> --- a/drivers/net/can/slcan/slcan-core.c
> +++ b/drivers/net/can/slcan/slcan-core.c
> @@ -689,15 +689,14 @@ static int slc_close(struct net_device *dev)
>                 clear_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags);
>         }
>         netif_stop_queue(dev);
> +       sl->rcount   = 0;
> +       sl->xleft    = 0;
> +       spin_unlock_bh(&sl->lock);
>         close_candev(dev);
>         sl->can.state = CAN_STATE_STOPPED;
>         if (sl->can.bittiming.bitrate == CAN_BITRATE_UNKNOWN)
>                 sl->can.bittiming.bitrate = CAN_BITRATE_UNSET;
>
> -       sl->rcount   = 0;
> -       sl->xleft    = 0;
> -       spin_unlock_bh(&sl->lock);
> -
>         return 0;
>  }
>
> --
> 2.32.0
>
>

  reply	other threads:[~2022-07-21  1:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-15  7:29 [PATCH v3] can: slcan: do not sleep with a spin lock held Dario Binacchi
2022-07-21  1:58 ` Souptick Joarder [this message]
2022-07-21  6:30   ` Dario Binacchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFqt6zaMnfGhwxnnJrbW1eoiGy46-WNUe8H-iqztRmZW5Z8jfQ@mail.gmail.com \
    --to=jrdr.linux@gmail.com \
    --cc=bigeasy@linutronix.de \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jhofstee@victronenergy.com \
    --cc=jirislaby@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lkp@intel.com \
    --cc=lkp@lists.01.org \
    --cc=ltp@lists.linux.it \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=oliver.sang@intel.com \
    --cc=pabeni@redhat.com \
    --cc=rpalethorpe@suse.de \
    --cc=wg@grandegger.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).