From patchwork Mon May 29 05:58:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 100079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1306095vqr; Sun, 28 May 2023 23:12:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YEccwS/pvVkxJq9laQsgppbJt4MnChjFR5+Wq4xkCreVkMiA+jR6+O5RVpPZsPjRaLYbk X-Received: by 2002:a05:6a20:1601:b0:10b:8a3b:1680 with SMTP id l1-20020a056a20160100b0010b8a3b1680mr8677769pzj.29.1685340728945; Sun, 28 May 2023 23:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685340728; cv=none; d=google.com; s=arc-20160816; b=aoEo/7YP0guGOFRmAnLM5x37dMvUYYB1M92mOJ/wjRIqccRccbh5ly/SakrKIQAoDg JEoH1o+H3ag5fAX+IWrVZ85JS+f2hDOmu/GSoNv6CvVv4CePGc2krTEL/444bjU8mI7O RM2uLh2YuPpAlXqiEh7A463fKIHoyfF9JMTc0kDdM7bkiETCUKnyiyvDuE/YdnfEZZLB tEjWRDNumIEfB2jYXkqWO2XkcIsQ+O5m7/RxQL0WYf5HPRKzcPQguyizADgQ62QUj4bc 95Lvr1jKkvEo/Be6xyg1Bqgf2yVMP4hEskPgtnonYN8vAauz9qtUYSgWzZnyXifQxjg7 8SCA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=1rNNsFbbX0pydEx0mfhXKwzskrBT02Ah6NfUorn4NeY=; b=mNqPdc4H3WXxy5wiKqrjtNjbjZvXX+qBMKMhvRNX6h9Ei2MwqcaPKnEABFxHJgwET7 WofOB4QmSWVpThn9oKZnMPO3r3F/sKRwQ3FkJ0yPfXgi17q9LtUXyONCqOqIewxcAKuO q9LZ69zkt8CCbK9QXM/CnlMpX5n3KZC7/U4o1VIidX1LlIcUjovpvburX61LqBQMfdaC QbVMsllKMTU1UfZ3X53f5JmPf8fivtmtVWWbp8sIQxeLEJkJGusT3Am9BcyHJ6cRRfyW BLoEU3M5M2Ek9PMx1pRrVzP/mcTaMpheMbAvL5IRlT3Xhl/PEOY989MZBWMbiHQzFzYP u8AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=m22bL7la; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c20-20020a6566d4000000b00536e63c8643si1785540pgw.558.2023.05.28.23.11.51; Sun, 28 May 2023 23:12:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=m22bL7la; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229572AbjE2F6q (ORCPT + 99 others); Mon, 29 May 2023 01:58:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbjE2F6n (ORCPT ); Mon, 29 May 2023 01:58:43 -0400 Received: from smtp.smtpout.orange.fr (smtp-25.smtpout.orange.fr [80.12.242.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B7FEA8 for ; Sun, 28 May 2023 22:58:41 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id 3Vttql3Hd0h9k3VtuqAkIU; Mon, 29 May 2023 07:58:38 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1685339918; bh=1rNNsFbbX0pydEx0mfhXKwzskrBT02Ah6NfUorn4NeY=; h=From:To:Cc:Subject:Date; b=m22bL7laIJJVRSQwFiUatK4yYzwyY7/QY5ntEj/WJmyb9T36Sofu5xbL354cKIcrV Vu4TynZuBvsyP0E+GGvhVO0L9vrOo5xYhX/pvH6QXRVfcHQQImV9XMYk5S+GKBz9kG wTu7pEiykUX6on/HFKp9UrKsnvCfkRn38lzeTXufcb0LZsmFkZ8LWPW8uPkgWzXKCC 5XcgFDQg/z4yBZj1RFfQmGUh0eP/oAofgunMYxKFPiTJhyPhbwszpRBQ+2As+qA7oE r96t4CztFPEuJsJ+Qc1snC5ztx3dOtja/EjEWab4SAgaTNrrFhkNIC/CuFBcQvW3eO CPWkG3fUDxH3A== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 29 May 2023 07:58:38 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Mauro Carvalho Chehab Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , Mauro Carvalho Chehab , linux-media@vger.kernel.org Subject: [PATCH] media: dvb-usb: m920x: Fix a potential memory leak in m920x_i2c_xfer() Date: Mon, 29 May 2023 07:58:36 +0200 Message-Id: <1881e72f963ec25e35b34f3a0b4f3962681eb7ca.1685339897.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767207840148322874?= X-GMAIL-MSGID: =?utf-8?q?1767207840148322874?= '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 --- 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 fea5bcf72a31..c88a202daf5f 100644 --- a/drivers/media/usb/dvb-usb/m920x.c +++ b/drivers/media/usb/dvb-usb/m920x.c @@ -277,7 +277,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; } @@ -288,8 +287,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]; }