Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1864135rdb; Thu, 7 Dec 2023 10:41:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHog1mQkhbwyW4xNvGy9SC3lvVUpar1U0LCWQVMuCTehiXrTzYGRp3rBbF9F6ukgudpwAbo X-Received: by 2002:a17:90a:f2d0:b0:286:6cc1:5fd1 with SMTP id gt16-20020a17090af2d000b002866cc15fd1mr2477740pjb.84.1701974480704; Thu, 07 Dec 2023 10:41:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701974480; cv=none; d=google.com; s=arc-20160816; b=IFPV5NBZqs98Y/TP4vT5vBUIeDQx9Xp/oo7GW98O4qeiS4ZFSrR3SxpJ8ntUgSWWLs caPWDVQsaphIlyHVymaTmsEkJ87cwqM0p5AZneWwSHSJDsQyKeANmB2vIpmadyXgJIlm Da9xQXKiYRCLzi8nqPIVeZSqlw9wWFKU12KV/oa7t5FFICrW8lUaQIcdY0kjzRy38X/t yuVTULrTmanH2Csk0klCxRgLJ267cRfYObhxsV9gk19OPq6pvmJoZMDXdDgh69IT6vns XxKH8nNG+i5KK2HpCbMcBnt984gaJDIKGk6S0+t2+vNEFBHnr8eh7aSRJ1m6rmZO2A7c wtXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=asCN+qdel2G2qPx7fq1JN1wR4gEECtwJ8qZrHlvtAMo=; fh=M9z0d6MEBGN/mqHvJV4os7SrIwfI22g3X5T/JA67l+E=; b=c5r+jfnmpflkpEMWfhaU0/5Gg7+/jSS462S5AhY2L/Af3yxVpm4njgzQ+1YxdmrFBf aCx85ykobgXnokJbGChaEUSYHo39FqWjNGowaSinOKG3ZRwj63q0rGY/4YIMPXLuuX7v 66oFSCC6orF4buO5B9l+h0eaxPh8TlJ9jQKDkLyzcsShFrWU2wWegoBx4C4KpYOD1BNX p+L8uSQkkuWfTcp8qnFeG+MaMRzmX5+Fx9UjGsTO6CszCQN0d+P11KLQXRE29RAw835X P486IB37oza22e/RWOl51IkKjRJVaBLB30UStw3gUxrEmz2gorFMnyB7TpcGXpFkJgwC CVIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=K22n2qR2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id f11-20020a17090ab94b00b002869a5326ddsi1525233pjw.75.2023.12.07.10.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 10:41:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=K22n2qR2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 51D4181DE6B0; Thu, 7 Dec 2023 10:41:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233081AbjLGSlF (ORCPT + 99 others); Thu, 7 Dec 2023 13:41:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233077AbjLGSlC (ORCPT ); Thu, 7 Dec 2023 13:41:02 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56D46171F; Thu, 7 Dec 2023 10:41:08 -0800 (PST) Received: from nicolas-tpx395.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nicolas) by madras.collabora.co.uk (Postfix) with ESMTPSA id 731886601F0A; Thu, 7 Dec 2023 18:41:05 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1701974466; bh=WcT7DiTTNQxZhHjWft90cTmZ9KR+kldp0Vqu91bJDwg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=K22n2qR2PEZXpMPa0J1s535f4oylKH2qEDoXEc912HbKGwA0JRiyJwoAGS8WRVv/m cOZ02Gw8sW0UKZz4mPJFUpYM+orhr+J4sriwvAdQTZyctYc2R6rmyVu1QbQfGDgpAR NxKIZf60oC0yPrjdbA8tF4AzAXR9D6/utFylQD1SC7Bwff4o1NMD0vr+gMRm7lQQXf bn7kAjFRsPDBcnkgb/rCGeEhv2kfI93LQR2/IgtZhNTKaqqfOrbYuLtwdrIYPoEcJE zksYO95i08ihxbUUbDsNsgbwu1V9LpD6FFOZuPgNs/rBH/Zpa0ljCFIDdsay+/Tv2b yN4Tw1eWyVo+g== Message-ID: <64d946710b3f3e14bfeb3fa95db01a99e244f264.camel@collabora.com> Subject: Re: [PATCH] Fix memory leaks in wave5_vpu_open_enc() and wave5_vpu_open_dec() From: Nicolas Dufresne To: Robert Beckett , Zeng Chi , nas.chung@chipsnmedia.com, jackson.lee@chipsnmedia.com, mchehab@kernel.org, sebastian.fricke@collabora.com, hverkuil-cisco@xs4all.nl Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 07 Dec 2023 13:40:56 -0500 In-Reply-To: References: <20231204091649.3418987-1-zengchi@kylinos.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 07 Dec 2023 10:41:18 -0800 (PST) Le mardi 05 d=C3=A9cembre 2023 =C3=A0 17:36 +0000, Robert Beckett a =C3=A9c= rit=C2=A0: > On 04/12/2023 13:55, Nicolas Dufresne wrote: > > Hi, > >=20 > > Le lundi 04 d=C3=A9cembre 2023 =C3=A0 17:16 +0800, Zeng Chi a =C3=A9cri= t=C2=A0: > > > This patch fixes memory leaks on error escapes in wave5_vpu_open_enc(= ) > > > and wave5_vpu_open_dec(). > > Please avoid sending twice the same patch. This is still a NAK. >=20 > tbf, this is a different patch, concerning the allocation of the=20 > codec_info within inst, not inst itself. I've stopped after reading an identical subject line. I can apology for not noticing the difference, but I think an effort from the submitter could certainly help in the future. Nicolas >=20 > > regards, > > Nicolas > >=20 > > > Fixes: 9707a6254a8a ("media: chips-media: wave5: Add the v4l2 layer") > > > Signed-off-by: Zeng Chi > > > --- > > > drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c | 5 +++-- > > > drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c | 5 +++-- > > > 2 files changed, 6 insertions(+), 4 deletions(-) > > >=20 > > > diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c= b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c > > > index 8b1417ece96e..b0a045346bb7 100644 > > > --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c > > > +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c > > > @@ -1802,9 +1802,10 @@ static int wave5_vpu_open_dec(struct file *fil= p) > > > spin_lock_init(&inst->state_spinlock); > > > =20 > > > inst->codec_info =3D kzalloc(sizeof(*inst->codec_info), GFP_KERNEL= ); > > > - if (!inst->codec_info) > > > + if (!inst->codec_info) { > > > + kfree(inst); >=20 > for consistency, would be better to jump to cleanup_inst. >=20 > Also, maybe consider embedding codec_info=C2=A0 in to struct vpu_instance= to=20 > avoid the double alloc. I've not checked whether this is viable=20 > throughout the code, but from a quick scan of the original patch, it=20 > looks like it is always allocated and freed alongside inst. >=20 > > > return -ENOMEM; > > > - > > > + } > > > v4l2_fh_init(&inst->v4l2_fh, vdev); > > > filp->private_data =3D &inst->v4l2_fh; > > > v4l2_fh_add(&inst->v4l2_fh); > > > diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c= b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c > > > index f29cfa3af94a..bc94de9ea546 100644 > > > --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c > > > +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c > > > @@ -1546,9 +1546,10 @@ static int wave5_vpu_open_enc(struct file *fil= p) > > > inst->ops =3D &wave5_vpu_enc_inst_ops; > > > =20 > > > inst->codec_info =3D kzalloc(sizeof(*inst->codec_info), GFP_KERNEL= ); > > > - if (!inst->codec_info) > > > + if (!inst->codec_info) { > > > + kfree(inst); > > > return -ENOMEM; > > > - > > > + } > > > v4l2_fh_init(&inst->v4l2_fh, vdev); > > > filp->private_data =3D &inst->v4l2_fh; > > > v4l2_fh_add(&inst->v4l2_fh); >=20