Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1419699pxb; Fri, 10 Sep 2021 05:39:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyarrtciaDg1mMMV3FqD3wwSFUgfYR9MpXtpA/cw0OHEryETBBhrkemPM3PDNoNciYiw6O3 X-Received: by 2002:a05:6638:619:: with SMTP id g25mr4326708jar.38.1631277594117; Fri, 10 Sep 2021 05:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631277594; cv=none; d=google.com; s=arc-20160816; b=MJ04Kkmmjb/BVtKxKkUYGVQTpcIvnFqD/UHKqz7XUlgv2D5kyD24PR0UND8IvfsHdd /w2lNJqZhEVWdy3h6m+MSC5Jd/9lZ6Ntvwz4eI2lliQIW+d8e+VKP7Q1mekNj5/B1CF6 mUTQbu5TQSeWkjUZk6caJ7URObXRAAa+axxqSrCYgGptsqE3GglJSAzdlj448ub6elSR FE6JlTjoKjAn9SwQcnEy/uKGerqvQJFTRsAcZuEAo/9fajD9YZiVcuUp+AKpLCGR6ftQ ebtbSQvUyYxL67aMCfrPdHHzrURDpsYral0dSrFKrnesvUkUoBCqSmcXwVGxhPiMxfYz 5I3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s4An9/oI/Fvuu5oiofyBgiOdJVDjTrRSpG2yHrjyj9k=; b=kwkDWD6PRYCS0UvnPCen47EQye0JR0cOqVm2/J3ojaPteOi9MLIdqUIcQxPW9jq1i2 1qRw+Ao0SzvRxxCSQpnlbhM3nNOXwVI09oyXxsfPAxzCWnM1vK1IF4g/1OB2udI26dUe E8zsbP+pXaDs7R+jEStndpl5BE7FSq4HEMT3jSO59Um0QEQF9bCyo8LSi3PJBLxIGHrf FE4tuCgkqzLLvZiycBMleJiTbY/qJOM9DKnhmjH6ZD0cnrVxHK9M63MJZETF6Z8lBIZL Hh1dedOEzw0Ml5D4NR1vDt2GZbkNACqHuU1FwITS4/e2OEfcEvjoog+zKdVqOXNrsoLZ OsZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l9BaUI5G; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e11si4782475ili.46.2021.09.10.05.39.42; Fri, 10 Sep 2021 05:39:54 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=l9BaUI5G; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234637AbhIJMil (ORCPT + 99 others); Fri, 10 Sep 2021 08:38:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:54634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233741AbhIJMg4 (ORCPT ); Fri, 10 Sep 2021 08:36:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C2AD86121F; Fri, 10 Sep 2021 12:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631277333; bh=HRYt+w4rh3mflXhyz3JiNRj8hMqLQ2bq6430B8eWofc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l9BaUI5Gq88Bc0lklUir+My0Dx6v0IOxkwoN1mugSTlolhqZ621y3ZWiVyYfgCs2G SjAqTKEyR96A2TsoPPTVLK8vdl1v8pLutDDPw2UMA6uJKKx9m3wR6aXBJoC9w89Zho +t1EaOoi8xFiJFkFqs8kqDbfBaePP25zWTn1U6SU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Rix , Johan Hovold Subject: [PATCH 5.4 23/37] USB: serial: mos7720: improve OOM-handling in read_mos_reg() Date: Fri, 10 Sep 2021 14:30:26 +0200 Message-Id: <20210910122917.926396667@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210910122917.149278545@linuxfoundation.org> References: <20210910122917.149278545@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Rix commit 161a582bd1d8681095f158d11bc679a58f1d026b upstream. 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. Make sure to clear the return-value buffer also on allocation failures. Fixes: 0d130367abf5 ("USB: serial: mos7720: fix control-message error handling") Signed-off-by: Tom Rix Link: https://lore.kernel.org/r/20210111220904.1035957-1-trix@redhat.com [ johan: only clear the buffer on errors, amend commit message ] Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/mos7720.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c @@ -226,8 +226,10 @@ static int read_mos_reg(struct usb_seria int status; buf = kmalloc(1, GFP_KERNEL); - if (!buf) + if (!buf) { + *data = 0; return -ENOMEM; + } status = usb_control_msg(usbdev, pipe, request, requesttype, value, index, buf, 1, MOS_WDR_TIMEOUT);