From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E0F019F137 for ; Sat, 28 Mar 2026 15:17:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774711077; cv=none; b=gRM6UkWTUButoEBMqvVERXAsVBp7H9BUOdyLlxBg6Kmxhlr5K4+gQoIkn+yz2Wu41vDuYKYMILZ63kVnRJvMl7kx3sBDVZfbBhJtpttj0Aw1KDat3iCsG3gwTkkVEIU73jaV7UQmxvFzNwzh4mMsEND9qZMJBTtiA/J4sVEPMlc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774711077; c=relaxed/simple; bh=A6MoI/96KtmHHQEY1kMP2uWxdbmW5+XGXps7ROfY0nU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U5DeZUVV913B/8pIZtEFFKZyVxzxn+zbvgL2YWo9Ac5FNSsDuH0D7NnTJ3wIzbGn43tDaj5MMeNb6lRv1tkwNNwrsquV1N8T4uPzxzCdcjAR44CJaxyKSfO6geHnfCqYJrNez04PiNHI/XBaemsCV0Bi8Zm2Nrx+6Iq/+jUY9qY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JON7d+dp; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JON7d+dp" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-667de793310so5096309a12.0 for ; Sat, 28 Mar 2026 08:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774711075; x=1775315875; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MorpkP6r/T60MTiGCUcfsot6ur/wG/ccNFtLOYY+Uxo=; b=JON7d+dpXLfoM6EKZIK+hHpghTwEgVjgt5ZvAbVVOcI24S6Ej/TL7Y0ABIRfOfE8Lt Rk8PjC+oi9lXoTk+5rz3IJbEN1aeq1J2MWQ61avyjoYBRLvxOvl8cFu7okIw3Va/xToU XyEeqzqUHvrYppKFMhnAvBQkKwL/6rOLmjE1Hll5KMpuRX4dMFqgmaezy0NK+z25ZvwJ reOvHkIiqzm/WTp1aScznaowdICI7U1t8gJKPr4x7Rr5X21axDEcMYfM4hXpjmhSC5do xA2+ct2UeIP0e4sBe1vH/MXURuaKux8fFWUI3DgSb9LD6Y4HZc6Lj4UaHOvayMeT2019 oeEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774711075; x=1775315875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=MorpkP6r/T60MTiGCUcfsot6ur/wG/ccNFtLOYY+Uxo=; b=YEQYdm+CqrRutzIVkFr02RYyyAiy4+ZENCvd6bwc1aHeo88TrSRHZqQ6SVkfHndYbs wghf6t6pVjbqHkUx8RNVkhV/35FeuOrNRn848M8JGaluQtsCnvozsa7e4V/XdKvV2DMA baPBknI8Ve5+s7ebuR1LnWOugeveQ/p5P87IsfqX3llTgoWkYr+IKpF5ep1BvDSkl3xV 0b0rWisEEuo1kKVlfJTYXqviioxKaONgILHc2uqvQV7r+w1e5go43igxzAf3H5tB4yQ6 oSAX2IPPcLT+Rck7nViaxiuFG9Y0wZqypyNpxvcoTBH1sfOxrEB4HOMWFynKfzO2c1G/ NF2A== X-Forwarded-Encrypted: i=1; AJvYcCUoKRnDiGoLtzSPg8w9Bofpshl4pzQwq6S6d/YcdQwnBWP6MtfqrozuMmtyALeWvCE66t2zfpBM/mz9p30=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2tcrkPlFTRQ5M2X0Vm8yUGLRG93yPJ4Cn26n/MbsPoOT1xL5u viPvqlgufYiu4VAIkxg5wCkWZcbXPfc/edfRujkXvhZsJOAjNLofSINvZk307h8cN4U= X-Gm-Gg: ATEYQzzdElgV6fo3qE7xpDDpxR2wPZtKKwLwtr9FPAvHgFFrvaDjjXYkl+lng9cAPjL VUf2rUdZv7HnBUglxhRmXZEAr0BIMi7R3o5jgf4FpmEijt/ssiwUci9/h5U6LxI1r9w9QLLrpQD Ci4uzehZItBWqW9asZTPcZTtfeg9YxekZiD6JPUNXgyJ1e4Q41g3pL0JOirE5cfhzMxmiOrnOZI cd7+lIKrGCTbFMBrbLyOwbLEmnTcT6BKrneVXlDnfdY6kjtdOAGXailvRT/haWul7gLuKErDVeD RkC8wcMg0mSRjrnQhP+vCLH12o2oZkVZxsHRko6yX3eieg4WgpRwROKuxIKv75lTW5mviSiviQm 1xGWZg4aQKbATVV/KuOjdfDIo+kNV5QHSdePsIOgTo/WLm+oHPdRmU0mZcDfy6kcjI7MGz0+wL8 lwaVZqkAmTtXY5WVJNLJh2C0gHGSmp3fCdeD8lilXIIU2o1gw2H0MiVLYMvxDoKWWFdaxTZkNvh wf7dvV+NWQTY7ecXAwXq4o= X-Received: by 2002:a05:600c:6287:b0:485:3b5b:eb8 with SMTP id 5b1f17b1804b1-48727ef6617mr104982175e9.26.1774709240531; Sat, 28 Mar 2026 07:47:20 -0700 (PDT) Received: from dohko.chello.ie (188-141-5-72.dynamic.upc.ie. [188.141.5.72]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43cf21f279bsm5077450f8f.16.2026.03.28.07.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2026 07:47:20 -0700 (PDT) From: David Carlier To: kwliu@nuvoton.com, kflin@nuvoton.com, mchehab@kernel.org Cc: linux-media@vger.kernel.org, openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, David Carlier Subject: [PATCH v2 2/2] media: nuvoton: npcm-video: fix memory leaks in probe and remove Date: Sat, 28 Mar 2026 14:47:17 +0000 Message-ID: <20260328144718.68282-1-devnexen@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327221905.267410-2-devnexen@gmail.com> References: <20260327221905.267410-2-devnexen@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit npcm_video_probe() allocates the npcm_video structure with kzalloc_obj() but never frees it on any probe error path or in npcm_video_remove(), leaking the allocation on every failed probe and every normal unbind. Additionally, when npcm_video_setup_video() fails, the reserved memory association established by of_reserved_mem_device_init() in npcm_video_init() is not released, leaking the rmem_assigned_device entry on the global list. Fix both by adding kfree(video) to all probe error paths and to npcm_video_remove(), and adding the missing of_reserved_mem_device_release() call when npcm_video_setup_video() fails. Fixes: 46c15a4ff1f4 ("media: nuvoton: Add driver for NPCM video capture and encoding engine") Signed-off-by: David Carlier --- drivers/media/platform/nuvoton/npcm-video.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/nuvoton/npcm-video.c b/drivers/media/platform/nuvoton/npcm-video.c index 5c6bddfe8073..87b09979cc52 100644 --- a/drivers/media/platform/nuvoton/npcm-video.c +++ b/drivers/media/platform/nuvoton/npcm-video.c @@ -1749,6 +1749,7 @@ static int npcm_video_probe(struct platform_device *pdev) regs = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(regs)) { + kfree(video); dev_err(&pdev->dev, "Failed to parse VCD reg in DTS\n"); return PTR_ERR(regs); } @@ -1756,33 +1757,44 @@ static int npcm_video_probe(struct platform_device *pdev) video->vcd_regmap = devm_regmap_init_mmio(&pdev->dev, regs, &npcm_video_regmap_cfg); if (IS_ERR(video->vcd_regmap)) { + kfree(video); dev_err(&pdev->dev, "Failed to initialize VCD regmap\n"); return PTR_ERR(video->vcd_regmap); } video->reset = devm_reset_control_get(&pdev->dev, NULL); if (IS_ERR(video->reset)) { + kfree(video); dev_err(&pdev->dev, "Failed to get VCD reset control in DTS\n"); return PTR_ERR(video->reset); } video->gcr_regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "nuvoton,sysgcr"); - if (IS_ERR(video->gcr_regmap)) + if (IS_ERR(video->gcr_regmap)) { + kfree(video); return PTR_ERR(video->gcr_regmap); + } video->gfx_regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "nuvoton,sysgfxi"); - if (IS_ERR(video->gfx_regmap)) + if (IS_ERR(video->gfx_regmap)) { + kfree(video); return PTR_ERR(video->gfx_regmap); + } rc = npcm_video_init(video); - if (rc) + if (rc) { + kfree(video); return rc; + } rc = npcm_video_setup_video(video); - if (rc) + if (rc) { + of_reserved_mem_device_release(&pdev->dev); + kfree(video); return rc; + } dev_info(video->dev, "NPCM video driver probed\n"); return 0; @@ -1800,6 +1812,7 @@ static void npcm_video_remove(struct platform_device *pdev) v4l2_device_unregister(v4l2_dev); if (video->ece.enable) npcm_video_ece_stop(video); + kfree(video); of_reserved_mem_device_release(dev); } -- 2.53.0