From patchwork Wed Feb 21 04:37:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhipeng Lu X-Patchwork-Id: 203916 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp829748dyc; Tue, 20 Feb 2024 20:37:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXj1iB2Qu9fQdnx+MuGCNbc8Jqy5NZdKUVw+nvAfEcNXXmRejUQUSFCzc9ZjEnuIuVwfhkbEs5O6h6M3Y4yfzbvwwXLDA== X-Google-Smtp-Source: AGHT+IHK9SfW4G0Xk+A4MjiLCb1LTQtoHKJzCZS9dUlU3HCgO2qNGLTSuWPs9GrBgE3AfVL7HXYb X-Received: by 2002:ac2:42cd:0:b0:512:be7b:c921 with SMTP id n13-20020ac242cd000000b00512be7bc921mr3222999lfl.1.1708490278637; Tue, 20 Feb 2024 20:37:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708490278; cv=pass; d=google.com; s=arc-20160816; b=ivbMw3qItp1uFmiN2jy3oah7fBVNsNJjS3P8KLlawPfKbN4zw5EG3sVyVmdgzchDrk mrgO3zLWl4gkXuO7S+YRQBHnSOVAnNWAqVx9GoPgXLgHWqzr+VlUuY03L2f764MAnetx sXmFYLSGhuVB8ywr5n9MTua86Va2XJ4IGxnGleyvYJFtnbcsALn24XQbe43dYxZj687P aP7lMjF3L7G1m50D8AiErCloBPRzhQwsV8J+GjmwH6+KX2fsHheJZG65JYbt8MpsnZz9 QOGM7bRhhDMriW/mXk9pJV3mezHTp4gtLlQoZHFVlHFbVaWk3hYuykENofWnu2DN4zDm 7+vw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=qS50FKJ0FLAamvSbRiLCEq1b0QlOY632zx3yZIsA0vo=; fh=LZLbbcYcsqkz+LePR5VOYOpiexqz60hX4s0GtC31vHE=; b=a26GHS0OpGcvBcctl3spi77kBCms+X/xNUtbl8dRvNh/rxQ0UDSbgTQ+Rq9uspf5wZ xEAIxgqNw7LeaH3gSKxATxHPhiGgkUJeMcJsjXv4jGfB+GDVcsV6ddRmCIev7z/x+8vq VDW1prfdZrtT7vhlJ+pWOJTcRO/akvcD1F+88dyRdmlx+fO2L72ZEzV9ZtZFCJn43ZuW 8OYoICRXzk5/RJjx48D9A0pc62k6csznHzugbwsFCAppqTr63mOO8aUdneaQIsC7elpc 9RU5TjaVgjiExMrZ0q3+mEYEyQCXsuHWCE/heAGX/EWepHrZj3hlvV97sqnxnYmNHLho 5pcw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-74052-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74052-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z14-20020a170906240e00b00a3e62c60f0csi3083646eja.612.2024.02.20.20.37.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 20:37:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74052-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-74052-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74052-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3DD2E1F23426 for ; Wed, 21 Feb 2024 04:37:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4FCFC39AE1; Wed, 21 Feb 2024 04:37:38 +0000 (UTC) Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net (zg8tmtyylji0my4xnjqumte4.icoremail.net [162.243.164.118]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D81929A1; Wed, 21 Feb 2024 04:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.164.118 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708490256; cv=none; b=jL33yJShoMwuspLCoLu/WEx62BG3MI+boYowlo2ejF0K3x/+03wroacfIGQ9zRpGKK3rXQlRLXYMK7bCXpdM8b6A4ZBQyLVdZNk+IOdpnpmXLz6q0bynrQNB+s5p6Bmk7USlOlt94Arw3T80WudJUGJ2hy8oonzyrUa6SRNPPfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708490256; c=relaxed/simple; bh=imCS86KllHy88avep2fuGt2I0mBvfsYLEuJnfOLb0ho=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ujotxWYDGhCqvfS//uPE9tTZoBs48ICzJPSlBHSn34a61bbg/jNVyADYJRU7SCyyNsp4hFJop5kwt6eWylt/B4WDyLj2YLxMYs/Vv3Av30RhoZzX3skai4q0MlmhqdOsr/uW4ycxPCQie3+8YT4knASt2TZvhL44Ce2CQpvT7Po= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn; spf=pass smtp.mailfrom=zju.edu.cn; arc=none smtp.client-ip=162.243.164.118 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from luzhipeng.223.5.5.5 (unknown [125.119.251.150]) by mail-app4 (Coremail) with SMTP id cS_KCgCXtIMFftVl2Ax1AQ--.16686S2; Wed, 21 Feb 2024 12:37:26 +0800 (CST) From: Zhipeng Lu To: alexious@zju.edu.cn Cc: Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v3] media: go7007: fix a memleak in go7007_load_encoder Date: Wed, 21 Feb 2024 12:37:13 +0800 Message-Id: <20240221043713.3163043-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cS_KCgCXtIMFftVl2Ax1AQ--.16686S2 X-Coremail-Antispam: 1UD129KBjvJXoW7CFykKrWDXw1rKrWDGry5XFb_yoW8Xryrpa yUGFyUAryrKr4UWanrWw4DKa4Fyan5Cay3C3s3Zw4rZr15tFWDK3y09F1jgr17Ga12qw1S yr1UZr17uF15AF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkG14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7CjxVAaw2AFwI0_ JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67 AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8 JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x0JUSNtxUUU UU= X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791481902276896290 X-GMAIL-MSGID: 1791481902276896290 In go7007_load_encoder, bounce(i.e. go->boot_fw), is allocated without a deallocation thereafter. After the following call chain: saa7134_go7007_init |-> go7007_boot_encoder |-> go7007_load_encoder |-> kfree(go) go is freed and thus bounce is leaked. Fixes: 95ef39403f89 ("[media] go7007: remember boot firmware") Signed-off-by: Zhipeng Lu --- Changelog: v2: free go->boot_fw instead of bounce v3: set go->boot_fw to null after free --- drivers/media/usb/go7007/go7007-driver.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/go7007/go7007-driver.c b/drivers/media/usb/go7007/go7007-driver.c index 0c24e2984304..eb03f98b2ef1 100644 --- a/drivers/media/usb/go7007/go7007-driver.c +++ b/drivers/media/usb/go7007/go7007-driver.c @@ -80,7 +80,7 @@ static int go7007_load_encoder(struct go7007 *go) const struct firmware *fw_entry; char fw_name[] = "go7007/go7007fw.bin"; void *bounce; - int fw_len, rv = 0; + int fw_len; u16 intr_val, intr_data; if (go->boot_fw == NULL) { @@ -109,9 +109,11 @@ static int go7007_load_encoder(struct go7007 *go) go7007_read_interrupt(go, &intr_val, &intr_data) < 0 || (intr_val & ~0x1) != 0x5a5a) { v4l2_err(go, "error transferring firmware\n"); - rv = -1; + kfree(go->boot_fw); + go->boot_fw = NULL; + return -1; } - return rv; + return 0; } MODULE_FIRMWARE("go7007/go7007fw.bin");