[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y+UZQvuh8KR4gE4P@rowland.harvard.edu>
Date: Thu, 9 Feb 2023 11:03:14 -0500
From: Alan Stern <stern@...land.harvard.edu>
To: Prashanth K <quic_prashk@...cinc.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Christophe JAILLET <christophe.jaillet@...adoo.fr>,
Xiu Jianfeng <xiujianfeng@...wei.com>,
Pratham Pratap <quic_ppratap@...cinc.com>,
Jack Pham <quic_jackp@...cinc.com>, linux-usb@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] usb: gadget: u_serial: Add null pointer check in
gserial_resume
On Thu, Feb 09, 2023 at 09:13:37PM +0530, Prashanth K wrote:
>
>
> On 09-02-23 08:39 pm, Alan Stern wrote:
> > You should consider having _two_ spinlocks: One in the gs_port structure
> > (the way it is now) and a separate global lock. The first would be used
> > in situations where you know you have a valid pointer. The second would
> > be used in situations where you don't know if the pointer is non-NULL
> > or where you are changing the pointer's value.
> Lets say we replaced the existing spinlock in gserial_resume and
> gserial_disconnect with a new static spinlock, and kept the spinlocks in
> other functions unchanged. In that case, wouldn't it cause additional race
> conditions as we are using 2 different locks.
Not race conditions, but possibilities for deadlock.
Indeed, you would have to be very careful about avoiding deadlock
scenarios. In particular, you would have to ensure that the code never
tries to acquire the global spinlock while already holding one of the
per-port spinlocks.
Alan Stern
Powered by blists - more mailing lists