From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 C5DD339D6F9 for ; Fri, 27 Mar 2026 22:19:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774649956; cv=none; b=VfxI0r6Q6VRuitZDMdyekDfPeFTB/g+ooi25j826OM/ziXikjgw0g/oVttEEGKtyo4ppTCjC3juVXcELXdwnacv7tC7r1MqAbEHFpOeOzQrssgNKnR+WP5xpvDj8KIKjRBZS2tfPW9cdhsbSBLHqsLEJeWZQK9Qib7AdP84zG7I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774649956; c=relaxed/simple; bh=neL999lXG/lvtuo9ubfiRZGfekJKqnqC5wp1ETW2xBE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EZgpim0ca6aG9m69gR/9kjZYC7vkXJN1maVmaWfsYNnRkYvDhEtpGEdEc/64UqWLln/X5DzPDe9NyD/pTCcv7CxLJZkO7Jo4q5rpghE/lVvgyS/mTTKrn0OPDlUJw8ImjZ6riUCl0IQwz0bWC+cVIBp1Vi7y/pQJMWohzJm2LXY= 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=WjQ5jwRX; arc=none smtp.client-ip=209.85.128.52 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="WjQ5jwRX" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-486fc4725f0so24269285e9.1 for ; Fri, 27 Mar 2026 15:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774649952; x=1775254752; 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=m2youRr357rlRwtasZfNZwC9KNFZnZTwKHeGB3J4nWQ=; b=WjQ5jwRX4mbE6muof08caG2rYw/QK4mUJUCMCELsP+fb5SyDGgIkJtZScprOwG+jj6 tmrgRZVVVw3G01d49I2QdrcslycSkXL9voAOHAv+M7sz002kXSBDdAj5MRTtRFhsMIF4 ySDVe+p4Y57EsNbOtx6mPOwjBSSuq5CJdZA4mjqUwvccbgQu5jS32tr1JNRVwJ/TEKXH Q/qeBuc2o8ckTqhZmtyS8Fo76Ao7KNRvfa+yT1LUIiHKz22LLFBTp7QQ7F+9sM+BmkRi 3Ex4Ts7UHqhDsQjybtpQVTNOlJfGKR52rQpFUv4feJWPJIU/Q81w6oQXj9Ze9mKY/2wW 9Saw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774649952; x=1775254752; 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=m2youRr357rlRwtasZfNZwC9KNFZnZTwKHeGB3J4nWQ=; b=JXra6K+Li0m11AIHxpZxwAgbi/1n4gbT0qfBVydb19NZE2NbLg/SphMETzwRPB4yFt eBhxRUZ/bevQkxnKY0xwYJOTRaSgMyHYL+Yn1Ej2QP7bmWl6/HQnC1kU1uQUlDPZHwTK 0OW6XQiCgVBwp6IcKnVI2kJTYBCzm/aweaateCwQMOA9/uXQ7O2GCxUgEeFH9DFlzSHn +DxN5+zqyVqXDFHZiqJSOo1xEnMiW5MwcEKaklf7doU1n2rIAORyW2cY1hXSwvVYC+0L SER4NKQzb7LkiiK9JF1vGwLsvhLFfn2wy86rzMsyns+1SfES/TPgeqj17HtfZX3oDWmE 1zuQ== X-Forwarded-Encrypted: i=1; AJvYcCVz3P7lHyY3nNFk98kmJ6hg2XxHFH5JfjMvd15xiBi/mUgFHzBfmDeABjgieKcMusuEFjwiaM3XOTgHdVk=@vger.kernel.org X-Gm-Message-State: AOJu0YzAL2N5phs8go1SZNsvPeL1sBiyfLB411QHvPWb85nYL8ZZtZ3P hflQCW4rQErHdMcVvfrmtzsL7cMA9vP2bmH77VC25pzVAIGXu8vjzaAV X-Gm-Gg: ATEYQzy4BERPFva+60evi6Wny2tbINPpuPl8uH739mfnwKUYRHEBIplfzhhfzY7sJP9 u4YITSkuIE2fyXNGUE80nymcs/jSTSa53m6yPSMbqATUGqPEbGx24cK18DNaubzPnRy5Y3KtUcD StiGS3HUSWv4wDAlsrDdouCKE5YJ2Ee8tThrWjLsXuyYpqFUOOflWpliaGd9i7y5eAQOUZ22+3f jpq3EqyXW8b/DP1CQETVrJ7QR8jWzNu5hJ4u41ogJ92y6NZb+jxpRUm7bA4nJDoO6NIQD1005Dn Tb81AE2lYeBoVTtVcnyXA6KgXbFwmw/0rrmUkg1MDzyR11EK8KduuTKxjfZ1x2jEYtHT8MYtl50 lvmVjDry3akrKTv/zEcql/npcbjxDKBfRmZ2/YcXcXz1O3Ht0PpwLULQ6WVXO/ECGVRN+U73Mz/ khV0HOZFCpRcxbVFQEkJg4tPMc20wyNlWNFYP0kL9uBdZyOhQiX7U6039Mosj261KXjXXIwlY9K 0WbII/Li8KJ X-Received: by 2002:a05:600c:45cd:b0:486:fbc4:8fe2 with SMTP id 5b1f17b1804b1-4872912dd2bmr59241125e9.15.1774649951916; Fri, 27 Mar 2026 15:19:11 -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 5b1f17b1804b1-487306acb47sm8489965e9.15.2026.03.27.15.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2026 15:19:10 -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 2/2] media: nuvoton: npcm-video: fix memory leaks in probe and remove Date: Fri, 27 Mar 2026 22:19:05 +0000 Message-ID: <20260327221905.267410-2-devnexen@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260327221905.267410-1-devnexen@gmail.com> References: <20260327221905.267410-1-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: 7c3a5e744482 ("media: nuvoton: Add driver for NPCM video capture/encode 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