From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (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 B8D6738B129 for ; Wed, 15 Apr 2026 20:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776286202; cv=none; b=to72uZSOd4yGMPF3Fu1GRrDJFb3U+Q9EbxqrDz31B30QRcChX1bJbSb4AOpPIHI7KYs+Tv+I4KVCdGVMEhmbBVJnII6cxFw+OUVFXQasyuKkkDk4CmLPJcjvc5Mgek9tvHPT0R+nxMLeNLPvlDt18vzqS3oufg5QWHCTHsWikDw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776286202; c=relaxed/simple; bh=XPyATpRpP6Fw9JKvgIKVLeMTg5EY/XceYweZor7TSdg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qcR0XE3KS4OUmmVhmmVe5Ol3iUtgaJB+5XGgfw4U7E4ajlOP/DrimILXms5t5hrP4RthfeIbcS+iMuf60YQbRhA8So810KnSoIvmtLie0F4hH2hj6hdv4ddsSlsFnMznJz35NoezVQxtFelbVWgZyrZZDWJ99w8ufDO49dKIYuc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dvRAq16f; arc=none smtp.client-ip=209.85.210.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="dvRAq16f" Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-7d86eb7c854so3601228a34.3 for ; Wed, 15 Apr 2026 13:49:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1776286198; x=1776890998; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=fXRmZFUi3/NUGdrIU0HiWh6hUGnEEJ0BOLVJoZTzlo4=; b=dvRAq16feIyt2mDV03XY9P99ydpDN+LnSgdDiu9LzSOVQYjkv8M+2Zh4CSGX03tki5 GZ9ItndsswpCd4JWi37rzpFQK3Wp9xG98LETDEpwcKbfE9e9IV+KM8sYgPEKZd/yhhtO RQTxkPnXXE7dgnHiTjKGa+OrdeMcrYPxRLwZM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776286198; x=1776890998; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fXRmZFUi3/NUGdrIU0HiWh6hUGnEEJ0BOLVJoZTzlo4=; b=tRaVLKegF2UtLeK0UetZBYLb/zdpX62MbZFMFLF5eDArdTN9AZmCdW5R82sJzrp3rT VmDSBZv3A+rbNTiLWu9IjevKpHcMPFIAhbrynHi3QRlKM+iFMw5k7z2WS6PncAv27Cug 3gC/VFOsa/0DMnNWNVVYMdsn999PdcnvPrc0aDYI2FQh9RijRkVVnaawl/vYHwb3zgZp e4N0iXEi3tsc3CvQvUMhx0zy5t7/jcQgfSWhJ5bN6VrzGmCxYANf+vVIFJoyVxVOKIWG U0NJE2/gfTYCzJd5d2xV+OXi274l189JVmLDrtOm3TrGV/4tp7U6T2GI/tsxDKr2engq gdkA== X-Forwarded-Encrypted: i=1; AFNElJ/Oa4FKVXYh3ttKcLawJDOL/AzKVahh1JjFl1LbPSbXEwG+DOwrejwmE+6f+eSUggu46W2eU20=@vger.kernel.org X-Gm-Message-State: AOJu0YziBZ2tSy2wVyHpnTgGCoOslWZma2Aa13tlttBL/9b+CcfzzHHX f0fsf5bGfAfvHLDWXy8mmnmyj5Eq+Un+vpHEK34luLvoxJow4pkcfXi48pPkw6kX2UQ= X-Gm-Gg: AeBDietHEHREk3SsJXJXf7wQB2pKZYVazUE0CfHSxGG4bhkoX/zsDcort66/WfqEvf6 MUB4Ye+CyUtxcRyld5OF+8pPwfNn+TSEy/SXCaKckbh3YB2XXVMzPUUcP3wkY4JwJKoJuSu988O E5WXj0R3kaioJbxlHv23IuEsE+9BTJchlohOZ71E6RHyB9VZnZbneTBeR768lVO1Sad7VpLIU1I JqhRM8dm1fpjCk+rAVWFGcnc5KGTrgfbMKOyMNp1YlS66645r9qmG/WzUJsM73UJblO5TaoVB91 Jrmy7nKou3Qtze3k6HtjzywtD0jggbW784hLDfIEvedMGx+H3xgqypHZaHbARdmBn0VL6skXQ0D rhhgue0CkskzzJSlC1+ZJ+xpRxfSuE3fsAjvOTMdqkXnt5yiOMj9UBIO8LCh0eCWEGHC0tWzVpV 8CkLKtK5xv1m5ce5FXuyoj9gtQQOrzzVc= X-Received: by 2002:a05:6820:168c:b0:681:22fd:a589 with SMTP id 006d021491bc7-68be5a636d6mr12796440eaf.11.1776286198589; Wed, 15 Apr 2026 13:49:58 -0700 (PDT) Received: from [192.168.1.14] ([38.15.57.99]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-42689699dc8sm2210443fac.14.2026.04.15.13.49.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Apr 2026 13:49:56 -0700 (PDT) Message-ID: Date: Wed, 15 Apr 2026 14:49:56 -0600 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] media: vimc: fix reference leak on failed device registration To: Guangshuo Li Cc: Kieran Bingham , Mauro Carvalho Chehab , Hans Verkuil , Dafna Hirschfeld , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Shuah Khan References: <20260415154537.3451732-1-lgs201920130244@gmail.com> <75275f6e-8314-4dd6-a54e-95320c2224e2@linuxfoundation.org> Content-Language: en-US From: Shuah Khan In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/15/26 10:56, Guangshuo Li wrote: > Hi Shuah, > > Thanks for reviewing. > > On Thu, 16 Apr 2026 at 00:01, Shuah Khan wrote: >> > >> >> Can you share your manual review? >> >> Can other static analysis tools for example scripts/coccinelle support >> your findings? >> Did you try other static analysis tools in the kernel? >>> >>> Fixes: 4babf057c143f ("media: vimc: allocate vimc_device dynamically") >>> Cc: stable@vger.kernel.org >>> Signed-off-by: Guangshuo Li >>> --- >>> drivers/media/test-drivers/vimc/vimc-core.c | 1 + >>> 1 file changed, 1 insertion(+) >>> >>> diff --git a/drivers/media/test-drivers/vimc/vimc-core.c b/drivers/media/test-drivers/vimc/vimc-core.c >>> index 15167e127461..fee0c7a09c4f 100644 >>> --- a/drivers/media/test-drivers/vimc/vimc-core.c >>> +++ b/drivers/media/test-drivers/vimc/vimc-core.c >>> @@ -421,6 +421,7 @@ static int __init vimc_init(void) >>> if (ret) { >>> dev_err(&vimc_pdev.dev, >>> "platform device registration failed (err=%d)\n", ret); >>> + platform_device_put(&vimc_pdev); >> >> Where does platform_device_get() happen when platform_device_register() fails? >> >> thanks, >> -- Shuah > > My manual review was based on the platform_device_register() call > chain and its documented lifetime rules. > > The relevant code path is: > > ret = platform_device_register(&vimc_pdev); > if (ret) { > dev_err(&vimc_pdev.dev, > "platform device registration failed (err=%d)\n", ret); > return ret; > } > > and > > int platform_device_register(struct platform_device *pdev) > { > device_initialize(&pdev->dev); > setup_pdev_dma_masks(pdev); > return platform_device_add(pdev); > } > > If platform_device_add() fails, platform_device_register() returns an > error, but the reference initialized by device_initialize() is still > owned by the caller. The API documentation for platform_device_register() > also explicitly says: > > "Never directly free @pdev after calling this function, even if it > returned an error! Always use platform_device_put() to give up the > reference initialised in this function instead." > > So there is no matching platform_device_get() on the failure path. > The reference comes from device_initialize(), and platform_device_put() > is needed to drop that initial reference when registration fails. > > That was also how I manually confirmed the issue after the tool report: > I checked the platform_device_register() / platform_device_add() > implementation and verified that the vimc failure path returns directly > without calling platform_device_put(). > > I found this issue using a tool I recently developed. The scan was run > on kernel version v7.0-1262-g4fa12523f7bc. There are several calls to platform_device_register() all over the kernel. Did your tool find all other cases or just this one? thanks, -- Shuah