Re: [PATCH] usb: gadget: u_serial: Add null pointer check in gserial_resume

From: Prashanth K
Date: Thu Feb 09 2023 - 10:56:36 EST




On 09-02-23 08:39 pm, Alan Stern wrote:
On Thu, Feb 09, 2023 at 07:37:01PM +0530, Prashanth K wrote:


On 09-02-23 12:33 pm, Prashanth K wrote:


On 09-02-23 12:31 pm, Greg Kroah-Hartman wrote:
On Thu, Feb 09, 2023 at 10:31:50AM +0530, Prashanth K wrote:
In that case i guess we have to make port_lock a global variable
and take it
out of gs_port structure.

+ static DEFINE_SPINLOCK(port_lock);

struct gs_port {
    struct tty_port port;
-    spinlock_t port_lock;

This will require us to change all the spinlock(port->port_lock) used in
u_serial.c, what do you suggest?

Yes, that would be the correct thing to do.
Hi Greg/Alan, One general doubt, if we make the spinlock static/global,
wouldn't that be a problem when there are multiple instances, and also
multiple interfaces can use u_serial at same time. Asking this because
u_serial can be used by f_serial (gser) as well as f_acm (acm).

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.

Thanks,
Prashanth K

Alan Stern