Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07CA4C61DA4 for ; Thu, 9 Feb 2023 15:09:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230304AbjBIPJH (ORCPT ); Thu, 9 Feb 2023 10:09:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230034AbjBIPJF (ORCPT ); Thu, 9 Feb 2023 10:09:05 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id C784C46A1 for ; Thu, 9 Feb 2023 07:09:04 -0800 (PST) Received: (qmail 772764 invoked by uid 1000); 9 Feb 2023 10:09:04 -0500 Date: Thu, 9 Feb 2023 10:09:04 -0500 From: Alan Stern To: Prashanth K Cc: Greg Kroah-Hartman , Christophe JAILLET , Xiu Jianfeng , Pratham Pratap , Jack Pham , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: gadget: u_serial: Add null pointer check in gserial_resume Message-ID: References: <1675864487-18620-1-git-send-email-quic_prashk@quicinc.com> <482f2c32-41d1-f07e-ee3f-3eb9aee76ac7@quicinc.com> <542ee8a6-598c-ca17-6d75-5eca2b34133a@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Alan Stern