From mboxrd@z Thu Jan 1 00:00:00 1970 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 A7DA1CE79CF for ; Wed, 20 Sep 2023 12:04:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235136AbjITMEZ (ORCPT ); Wed, 20 Sep 2023 08:04:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235137AbjITMEY (ORCPT ); Wed, 20 Sep 2023 08:04:24 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA641B0 for ; Wed, 20 Sep 2023 05:04:18 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24EAEC433C8; Wed, 20 Sep 2023 12:04:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1695211458; bh=tRT5xyIxvoPEkBmiXy7cg+/DuHIcshIzGSxmv05+SKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V/SonQlh9Tb4VTV784gJtbSevhy6HAgzRvsC6eYuNZHM9izzp3Q8Ju8OuUsGmCpDw 6+HlFiXaaLVYtBUatvySevOZNTrNr0f//TqE++nqO4x1LOhIo8gc8xsc2lBnV06Iyw IyAIsXh0/698Ca3JpA7lzuO0oxXGevSpJzgZhpII= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christophe JAILLET , Hans Verkuil , Sasha Levin Subject: [PATCH 4.14 075/186] media: dvb-usb: m920x: Fix a potential memory leak in m920x_i2c_xfer() Date: Wed, 20 Sep 2023 13:29:38 +0200 Message-ID: <20230920112839.578654219@linuxfoundation.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230920112836.799946261@linuxfoundation.org> References: <20230920112836.799946261@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christophe JAILLET [ Upstream commit ea9ef6c2e001c5dc94bee35ebd1c8a98621cf7b8 ] 'read' is freed when it is known to be NULL, but not when a read error occurs. Revert the logic to avoid a small leak, should a m920x_read() call fail. Fixes: a2ab06d7c4d6 ("media: m920x: don't use stack on USB reads") Signed-off-by: Christophe JAILLET Signed-off-by: Hans Verkuil Signed-off-by: Sasha Levin --- drivers/media/usb/dvb-usb/m920x.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/dvb-usb/m920x.c b/drivers/media/usb/dvb-usb/m920x.c index 8a43e2415686a..2a421bd9912bc 100644 --- a/drivers/media/usb/dvb-usb/m920x.c +++ b/drivers/media/usb/dvb-usb/m920x.c @@ -283,7 +283,6 @@ static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int nu char *read = kmalloc(1, GFP_KERNEL); if (!read) { ret = -ENOMEM; - kfree(read); goto unlock; } @@ -294,8 +293,10 @@ static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int nu if ((ret = m920x_read(d->udev, M9206_I2C, 0x0, 0x20 | stop, - read, 1)) != 0) + read, 1)) != 0) { + kfree(read); goto unlock; + } msg[i].buf[j] = read[0]; } -- 2.40.1