Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3000898pxb; Tue, 12 Jan 2021 04:03:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3vxv3Ci49znBI6znWGccrXaIwj/b72ctC78uq5ZCYOkNypR8NMrqi47Deu55L85IAoEsu X-Received: by 2002:a50:84a9:: with SMTP id 38mr3077304edq.378.1610452994883; Tue, 12 Jan 2021 04:03:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610452994; cv=none; d=google.com; s=arc-20160816; b=c800U7uJesn88NwUmOSrgHJZj/ZcGulfoJ1o5V1VhE1Vi7H7qzLzeAsYovKrPAjoZw dr93xmlBSB5gupKiR23TSs8ScCqnFDWJJRMo5oUCkGsrY9Wx6ugzJaBBHMca0Ze34GQo 5TZT1VGtdCOROyUw+NWzt5IlSqHCR5hurDULLj3bA6fJw53k3dyL7B0+laREiXDkhMwG 5LAdli4ytEQ/jgmJo2w56xEQd9Ettxjz3dED+/eRKTPmBVQm0COjRngVBQRWAy6Oi/os 3oQpi5Ta4+gNDaEJOBd8dkBZHFxWLtWByl4yBE7AoRK+6+02SNB2BJ/il5y7obSBK03s 7Kfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wIe4LQGmVv1xBrEQPIeBqZw1dCDRM9titGU15zvK8+A=; b=DKxWxfoEwPhMfbYLs9Yu6Psx3BHKvceOrFVMnehAASq8gxQc2LIJL+7L+6Tven4p39 Cf1dkr8mQ/pUIBUk+POUOFVicRgdC522LiFSsbkYd0JpoyDCUMTjnZ1EW6Qftb3qKnLr zOooj8ETjkoB8BQeITSCsiVNGs/j+8ED+bxJjbz/9382tg8HrzB1uwvwrr7ns1kmoikH OCA9B43JRBeXsSS+78M0LwGOMU2fVlfkejUZsM/7xMGIwM7ekAZRU8rM1x68zhwmEQWS adDSF+kUT5QrIOdiwG3u+7ufpx2GyfTaHOqYGn5pmYZQVKHPkpNFgDlJGR6hFxawHavn 5dXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gLVL1JFZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s5si1044805ejz.284.2021.01.12.04.02.50; Tue, 12 Jan 2021 04:03:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gLVL1JFZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389022AbhALI6F (ORCPT + 99 others); Tue, 12 Jan 2021 03:58:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:58036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726890AbhALI6F (ORCPT ); Tue, 12 Jan 2021 03:58:05 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 70AC62220F; Tue, 12 Jan 2021 08:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610441844; bh=5tRdddFOBQhc/BLqX1deVT71d1tPhTHmXOX1cizkxbY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gLVL1JFZ03tcpsnuXRFI4xY/SE6dSaBtgn9sPLysmBvaZmRF1SCvFnoeKFpkCHRYH ch0Kk5c38IRElXG1DYKH8MhxE/3Nhce1Sk8TQDzxSDpSpS5ibUTtGJADUonpX9wpKN mXnJJ3fMcfTA5i34zsuYOyp73/bFALySZrrkItF49gbH4SYelzspkMm/SuPYbZ4p59 sy0gglCZz1viu+RYZ7qDArlomQJcxzST+mSGyaqlv+40ELZ3qwz1ADR+fvGqW2qBkg rk1lKfMBDHboSSZO3h9GQQ9PQcq4Qmuz7+xrxVbAmZDBUC2xAlzxd6GYTjsC6+WrHa p0ayWS3Hyl50Q== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1kzFUZ-0002xG-3t; Tue, 12 Jan 2021 09:57:31 +0100 Date: Tue, 12 Jan 2021 09:57:31 +0100 From: Johan Hovold To: trix@redhat.com Cc: johan@kernel.org, gregkh@linuxfoundation.org, natechancellor@gmail.com, ndesaulniers@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] USB: serial: mos7720: improve handling of a kmalloc failure in read_mos_reg() Message-ID: References: <20210111220904.1035957-1-trix@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210111220904.1035957-1-trix@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 11, 2021 at 02:09:04PM -0800, trix@redhat.com wrote: > From: Tom Rix > > clang static analysis reports this problem > > mos7720.c:352:2: warning: Undefined or garbage value returned to caller > return d; > ^~~~~~~~ > > In the parport_mos7715_read_data()'s call to read_mos_reg(), 'd' is > only set after the alloc block. > > buf = kmalloc(1, GFP_KERNEL); > if (!buf) > return -ENOMEM; > > Although the problem is reported in parport_most7715_read_data(), > none of the callee's of read_mos_reg() check the return status. > > So move the clearing of data to before the malloc. > > Fixes: 0d130367abf5 ("USB: serial: mos7720: fix control-message error handling") > Signed-off-by: Tom Rix > --- > drivers/usb/serial/mos7720.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c > index 41ee2984a0df..23e8162c768b 100644 > --- a/drivers/usb/serial/mos7720.c > +++ b/drivers/usb/serial/mos7720.c > @@ -214,6 +214,7 @@ static int read_mos_reg(struct usb_serial *serial, unsigned int serial_portnum, > u8 *buf; > int status; > > + *data = 0; > buf = kmalloc(1, GFP_KERNEL); > if (!buf) > return -ENOMEM; I added a clearing of the buffer to this error path instead to avoid the redundant assignment for every call due to something which will basically never happen. > @@ -227,7 +228,6 @@ static int read_mos_reg(struct usb_serial *serial, unsigned int serial_portnum, > "mos7720: usb_control_msg() failed: %d\n", status); > if (status >= 0) > status = -EIO; > - *data = 0; > } > > kfree(buf); Johan