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 1BE8FC64EC4 for ; Fri, 10 Feb 2023 15:48:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232841AbjBJPr7 (ORCPT ); Fri, 10 Feb 2023 10:47:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232818AbjBJPry (ORCPT ); Fri, 10 Feb 2023 10:47:54 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 0389F70952 for ; Fri, 10 Feb 2023 07:47:53 -0800 (PST) Received: (qmail 816769 invoked by uid 1000); 10 Feb 2023 10:47:53 -0500 Date: Fri, 10 Feb 2023 10:47:53 -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: <5ad875be-079c-7f91-ede9-68f954cc7f34@quicinc.com> <71f624df-5302-8276-2a2a-96223d4ba3c7@quicinc.com> <53d48954-3f7e-fd02-5e8e-2912c16565b3@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 Fri, Feb 10, 2023 at 12:26:52PM +0530, Prashanth K wrote: > > > > And this seems like a viable option to me, what do you suggest? > > > > gserial_disconnect { > > ????spin_lock(static) > > ????spin_lock(port) > > ????... > > ????gser->ioport = NULL; > > ????... > > ????spin_lock(port) > > ????spin_unlock(static) > > > > } > > > > gserial_resume { > > ????struct gs_port *port = gser->ioport; > > > > ????spin_lock(static) > > ????if (!port) > spin_unlock(static) > > ??????? return > > ????spin_lock(port) If you want, you could move the spin_unlock(static) up to here. It probably doesn't matter. > > > > ????... > > ????spin_unlock(port) > > ????spin_unlock(static) > > } I agree, that should work fine. Alan Stern