From patchwork Tue Feb 6 06:26:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhipeng Lu X-Patchwork-Id: 197202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1353402dyb; Mon, 5 Feb 2024 22:27:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXKz2Troi/WBVh9MoI2PIZ1hrV07Mbsd4x7bZXN81G5ylizQr+5uMcFCqVFrlR1OILEgMq X-Received: by 2002:a05:651c:782:b0:2d0:b758:93a5 with SMTP id g2-20020a05651c078200b002d0b75893a5mr755004lje.18.1707200850950; Mon, 05 Feb 2024 22:27:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707200850; cv=pass; d=google.com; s=arc-20160816; b=jWI4TxdpGuekPO3bcvp28qdPFumVRRe/+HiV+Tk8Sb8N361431C3wToL4GzyGF0TAJ L7CbrrlTcKqgqpT0Z97bva0cmziiYy74I30V6wjLmW3IiDabT5S7vEuV8Y6iKJMuI2Ph afWrnSbOr3A4U9YvRLTszI2cHwOzpo1xmfInHT2l12XZfhnTwy0bVbCDOELjjnmY5rJf ZSL09U0/XtXBd5Rm/EL3hulDXd9kyG5ne+pvfO63ArpVUE3bYApPWEWq7/iDWQdf3DUV XDVM/AFGsPV0CL/OKmu/6pFoSRXxPVUXq8zLm1mdxucKikVLJJekZOHpOqejyaujoP3h EHNg== 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=QfbsjEB/8P8O+dcvVo9C0429YE+9pL+J9sDRKDwOC+E=; fh=E86F87lt0ntxBS3J9p2T98bEhCw7Tf4hXMyb8+d3khU=; b=CR4qGs/Qm0jVthtsIHofHc5dbe0Z1ui0vEECo14ByagdiBo646aAx1BoskSp7tvzHo NyQm+z4bzCJzE9Scf7MmO5ATYP142lcfhzE+M2RW8qjKERg+5BZmZ1fZJHDM/Hz5cwzM d1isqdxw/o1RbwaYXcFfjU5119zo6VH/urDr2GbDKgiIPx1QLjqXgWFJNV0kjaVGNuVF x/5/QnEpBCfhK0h4DnVPd5mfMoWBzUQL3ahoAYpg8BNJduOoK1MmZtOlOb4IBL1Rx6du K/2/tNpEE3IsfX5jKyHe4cqsvkIfM0uwfa924TyCd9lg/HChyNyBEmHwJOPa1g3F/9o1 pv0w==; 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-54374-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54374-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCU7m4Am1T7NpSXJSU9r9bq38S2v9mstuuD9MyidWarHrmR1h8cnGMAzNq7EP6R06QEts9oifKUldKW5vE8Je8sv5kNSvw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l8-20020aa7d948000000b0055fb4b1c2bdsi766746eds.89.2024.02.05.22.27.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 22:27:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54374-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-54374-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54374-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 86E7A1F245FA for ; Tue, 6 Feb 2024 06:27:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9212D83CAB; Tue, 6 Feb 2024 06:27:10 +0000 (UTC) Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [52.237.72.81]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0432382C8E; Tue, 6 Feb 2024 06:27:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.237.72.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707200829; cv=none; b=ot3wfmswFaiy2inSMcfGKTeU9vdrItiqmaIukq3sV4EgrRs4FrUiqhBKhiNS0TzMhEtBETUl6m3uXllptkvZ5mCL8t8Z2Vi8I56GxCNcSEsQrS4KXIYVwzb0xw5f7YG2v1s307nlVCGyJ43nWvbJFdkzeheKtUOdeiD5DYBTo1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707200829; c=relaxed/simple; bh=Y0Vb9EsMMO9CTmr+tyVGA2S0952m1hbIPvBl4GMLjQ8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=kGeQASqmWCoNBt6rp3LCjtdN5J25r0dr2WesUP8Szjx1gnIrcxLYNiXqQAV72TSEYYhcb82xICK6zFTw3JqBst3DRNO62Cz2FeFDpWuVwlzdc9nMERC+FTx1tP+SyrY7huJmM69iSr5MWZMDsJr35LjrezTYrpwu5v298l3sNjQ= 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=52.237.72.81 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.120.152.49]) by mail-app2 (Coremail) with SMTP id by_KCgB3na0n0cFlzrtmAQ--.25714S2; Tue, 06 Feb 2024 14:26:49 +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] [v2] media: go7007: fix a memleak in go7007_load_encoder Date: Tue, 6 Feb 2024 14:26:01 +0800 Message-Id: <20240206062601.3126752-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: by_KCgB3na0n0cFlzrtmAQ--.25714S2 X-Coremail-Antispam: 1UD129KBjvJXoW7CFykKrWDXw1rKrWDGry5XFb_yoW8GFyfpF WUGFyUAry5Kr4Ygws7Ww1DKa90ya95Cay7C3s3Zw4fXr15tFWDK3y0vFyjgr12ka12qw1I yF1DZr17uF15ZF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 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: 1790129839435682496 X-GMAIL-MSGID: 1790129839435682496 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 --- drivers/media/usb/go7007/go7007-driver.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/go7007/go7007-driver.c b/drivers/media/usb/go7007/go7007-driver.c index 0c24e2984304..65d6a63068dc 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,10 @@ 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(bounce); + return -1; } - return rv; + return 0; } MODULE_FIRMWARE("go7007/go7007fw.bin");