Message ID | 20240206065008.3128493-1-alexious@zju.edu.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-54379-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1360859dyb; Mon, 5 Feb 2024 22:50:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFu7vyk+k6ESwoK64xaLEXHAeuP967bBSP+ne17xus6uHOcnI16Pgm+iFn2w4trZ1SwjMxT X-Received: by 2002:a05:6a20:258e:b0:19e:2993:793d with SMTP id k14-20020a056a20258e00b0019e2993793dmr890069pzd.17.1707202250960; Mon, 05 Feb 2024 22:50:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707202250; cv=pass; d=google.com; s=arc-20160816; b=YrqcxKzPsgU/QJ4J+Sky2osuJIuJkZBL+75d5NPMcmV2hAfnhbrM+mV901za+c4Kc8 hrktXnNNinAoeE7TXZF+DFcj9Z8fiY7LiSNzcDwByAC+Q1VWez5iFkl2NptTnNLrMLXZ FIdPsdzP6E1+2HoXiGNQLieQYJV0hQRb9AyzNeh2PWMD496TCImQd6lSZhJh3kKzFRYT LiE8503DlJwUE0SXZYx5ltKDA40WoarWRMN4PDe+mTKSufiql5UfChQCfLielqJeIgIF SfPXPVbxOOsSZHq5PjPZarmHVg2L6qlcsCS9BgflxLuNb1OfDqjAK8ac5VUydsp0UBg+ HgdA== 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=ei/w/Wua1PUqxfiSzbb1x6+L6CJXkfxChQEywSKuQLA=; fh=rLk0NH9T0PIChmaUScYcrkgneAti2SwgdNF2Phxfw4o=; b=sHGJjFxw2lieaUJMeGNPf3KGiBAWNAe/5WHk7DPnBY3PXC39T97Cwh8urqvaHGZ2Bk yZL7z+mSgBBCZHvD7Zit88IQlld4+tNAT/ZsDMf6M/uxrxjubPKtVHn+/lH3TJhDBme1 0SUMhV2w2AvPEVKfpet/egjx+LozPg5DXcKiXqMehOIMq4ws+eMbfNeuFwBbM7JA0gTT moYMAeUVwcbQoc5o+kQF52eLADnweB+Wm/xJoe25tpvgEuvHfEHAJobp8BWkhIMeKBVb /QNz00TCkHPl+EOJ6vIMAbOEcJy+0xwr/0uJ+bu/AtHw88pxf3TGWx/7B92erde4b1BA 6O2w==; 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-54379-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54379-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWAFGqOPONNwP1TMWBDF+mC5u3wHpKR/BGDTbZf7avdqpZTyg+fqwPCjd4UxdnW/oeFGOpdhBi9hEEF8cWzYk0pibsdqA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u20-20020a63f654000000b005ceb19326e3si1201238pgj.251.2024.02.05.22.50.50 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 22:50:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54379-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-54379-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54379-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BB9A6283FA8 for <ouuuleilei@gmail.com>; Tue, 6 Feb 2024 06:50:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C6F6128820; Tue, 6 Feb 2024 06:50:32 +0000 (UTC) Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [207.46.229.174]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D19AC12837C; Tue, 6 Feb 2024 06:50:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.46.229.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707202230; cv=none; b=k/A06JaQ5WXm3adAQma5waEmC4+dh7UgeTNYgA7N0I2UPIoSv1vIE5BqvtJ+FiMQwn1C6jZHKn2cfrUPQndVyB3Qs18E0ziDTaEwU54ZQ8Mc0p3boOIuR71WGDXQECdksF7EgVSPlSiMO5c5FyFkI6owLWOgQUi6GDZ+yw5hkWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707202230; c=relaxed/simple; bh=7dpSp+zf+TgwmI+FG8YzE/qqn6NFSm1DDTF7SG2gFxY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=cxAYMLQ8v8+AU1g/ctv74xktHufJbD+lNOXkHue4Vtw+5y4Gw5dT2nxwGsV1uLUJ7/dA/vpkfKDXeICiuU1rqUshsnax3Kx/FNJc6fwNnoXmp2EIEkevMccnbOeqZqBzgj7PKoqFcQNQAevvUkpvt/a7XEH6admrpfC5PZB2OAQ= 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=207.46.229.174 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-app4 (Coremail) with SMTP id cS_KCgCHhYWs1sFlzboNAQ--.51854S2; Tue, 06 Feb 2024 14:50:20 +0800 (CST) From: Zhipeng Lu <alexious@zju.edu.cn> To: alexious@zju.edu.cn Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>, Mauro Carvalho Chehab <mchehab@kernel.org>, 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:50:07 +0800 Message-Id: <20240206065008.3128493-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: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cS_KCgCHhYWs1sFlzboNAQ--.51854S2 X-Coremail-Antispam: 1UD129KBjvJXoW7CFykKrWDXw1rKrWDGry5XFb_yoW8WryfpF WUGFyUAry5Kr4Ygws7Ww1DKa9Yyan5Ca47C3s3Zw4rZrn8tFWDK3y0qF1jgr17Ca12qw1S yF4DZry7uF1UZFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvm14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7CjxVAaw2AFwI0_ JF0_Jw1lc2xSY4AK67AK6r47MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r 4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF 67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2I x0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2 z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnU UI43ZEXa7VUUJUUUUUUUU== X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790129839435682496 X-GMAIL-MSGID: 1790131307756859844 |
Series |
[v2] media: go7007: fix a memleak in go7007_load_encoder
|
|
Commit Message
Zhipeng Lu
Feb. 6, 2024, 6:50 a.m. UTC
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 <alexious@zju.edu.cn>
---
Changelog:
v2: free go->boot_fw instead of bounce
P.S. I'm sincerely apologize for sending a wrong v2 patch with no
change applied. I forgot to add the changes to commit and missing
it when checking. Please use this patch as the version 2.
---
drivers/media/usb/go7007/go7007-driver.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
Comments
On 06/02/2024 07:50, Zhipeng Lu wrote: > 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 <alexious@zju.edu.cn> > --- > Changelog: > > v2: free go->boot_fw instead of bounce > > P.S. I'm sincerely apologize for sending a wrong v2 patch with no > change applied. I forgot to add the changes to commit and missing > it when checking. Please use this patch as the version 2. > --- > 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..c0a47e596339 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(go->boot_fw); I think it is best if you add this line here: go->boot_fw = NULL; It makes the code more robust in case go7007_load_encoder() is called again. Regards, Hans > + return -1; > } > - return rv; > + return 0; > } > > MODULE_FIRMWARE("go7007/go7007fw.bin");
diff --git a/drivers/media/usb/go7007/go7007-driver.c b/drivers/media/usb/go7007/go7007-driver.c index 0c24e2984304..c0a47e596339 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(go->boot_fw); + return -1; } - return rv; + return 0; } MODULE_FIRMWARE("go7007/go7007fw.bin");