Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1806131rdd; Thu, 11 Jan 2024 09:43:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHs0X2O7i8yUm7RQ0l7jYuShJNnHxwhSUVSISMGnEeVfuAYIckoyZEDuvPEAtpYpIkwz8tr X-Received: by 2002:a05:6e02:13d0:b0:35d:6211:80cd with SMTP id v16-20020a056e0213d000b0035d621180cdmr41298ilj.14.1704995002521; Thu, 11 Jan 2024 09:43:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704995002; cv=none; d=google.com; s=arc-20160816; b=BjRLG/M+FK6mwtyQmrkBxV/Ol4/YyNzKIAPyP1vcRO6seoGPWiGW1li2z/3XwL0x4B QcnYN9yQn1aAbqRypafI5fxlSkOKS+ovAsLVrkl9mlbuehvl8/DLqvIP3HYTAZfM4AQS vALG4Am202bbaNGTMn9DeLSQfEDNP8hEdP0Ts7nJ6DXYbkngrq1zPrRshSwU4HeWX73j QkgaNt4FdB0QzCdt5Li/r+S74fbhelOdE7OUQBjxoSZMypjiHkzRRxqJdtip+CWOLcvE dPCE96GeefQ76yRJgzpC1zPuf8u5PqKnVZ5x5bN7mt3FPlOPXoquHVTbu3TPNlLk6iYk VM4Q== ARC-Message-Signature: i=1; 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:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=wfkF20XtU2uKHOr894bl2qdm5MCSPnXp9LcvNFh7wVg=; fh=mUj05T8BpSfnUDsoaiUOAXy8WvxWGSPtXX2CZkbD0V8=; b=Psp3/Eg0Aqtbr/oj1m8DmW0RuQW7PO0Zde7TK3Meea+iDG60VYTvB+U5f+WV6Fp4rQ nnqcyoo70KlZCX+VPl/cW7ASWCio0k6QzY3WWsujHDQtLhKOSinbNrOhnaPpZJtK+HVZ Wxxq7mGi2cLnyw103bFaoywCw9ouk5ldbEtfWDJfTm+py3fMfS5BqYbcFOx+N1hkUgrV VnQNGCwpePmnmo3AuDbsSejqzGBCpxG1cTZPGZYfHn3nZ19TlZBKmtVJeKlVB5rCcZSp 3hW38tUvGWpJPl77W7A7XLHCv+uLNaumnUPSXLQk4Fisn1P4ibGb8LZMr22rTS3SQcgm LEGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="H/g+FFK6"; spf=pass (google.com: domain of linux-kernel+bounces-23944-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23944-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id bw16-20020a056a02049000b005cda184c288si1720720pgb.212.2024.01.11.09.43.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 09:43:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23944-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="H/g+FFK6"; spf=pass (google.com: domain of linux-kernel+bounces-23944-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23944-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 2609CB26171 for ; Thu, 11 Jan 2024 17:40:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEFB552F73; Thu, 11 Jan 2024 17:40:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H/g+FFK6" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AE7C3A1BE; Thu, 11 Jan 2024 17:40:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3A20C433C7; Thu, 11 Jan 2024 17:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704994839; bh=YpwQWCnVnBBUqaWv4bCZdTrssGsplr32Ot76UMUI56k=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=H/g+FFK6nTrDAxLRA+VBZOpXbMiBXYh+19KibTOdCTjWQbuON45UT/bze6yen1iVf bmBp7ToVw35MTC/kLxOiPIZ2sPXb1eF1kbe3CIHDZUUhpNlEeOKrMI8kexAny/B6ML jAg7by1QGy6GIDBr0wwu9/P831XSc643oHzfU/KcLSidmUWLt4ulseGO3NqwduuNYQ kc0iub6ufQd1TgzmSGnQCoOrAWGyvB4yNP7srNINsnJE/mUyMgzNAHPepDY/cInZqJ L8XEXFDlJpogAzsNPkf8L+wdtCxZu60LnO3yo3GDnwI/HoMzoJQFqgAWs/N+m9CCJ+ Gw3oql/C8a4zw== Date: Thu, 11 Jan 2024 18:40:35 +0100 From: Mauro Carvalho Chehab To: Nikita Zhandarovich Cc: , Subject: Re: [PATCH] media: em28xx: return error on media_device_register() failure Message-ID: <20240111184035.18a6ad4b@coco.lan> In-Reply-To: References: <20240110173958.4544-1-n.zhandarovich@fintech.ru> <20240111074905.67d61b00@coco.lan> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.38; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Em Thu, 11 Jan 2024 07:10:10 -0800 Nikita Zhandarovich escreveu: > On 1/10/24 22:49, Mauro Carvalho Chehab wrote: > > Em Wed, 10 Jan 2024 09:39:58 -0800 > > Nikita Zhandarovich escreveu: > > > >> In an unlikely case of failure in media_device_register(), release > >> resources and return the erroneous value. Otherwise, possible issues > >> with registering the device will continue to be ignored. > >> > >> Found by Linux Verification Center (linuxtesting.org) with static > >> analysis tool SVACE. > >> > >> Fixes: 37ecc7b1278f ("[media] em28xx: add media controller support") > >> Signed-off-by: Nikita Zhandarovich > >> --- > >> drivers/media/usb/em28xx/em28xx-cards.c | 2 ++ > >> 1 file changed, 2 insertions(+) > >> > >> diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c > >> index 4d037c92af7c..dae731dfc569 100644 > >> --- a/drivers/media/usb/em28xx/em28xx-cards.c > >> +++ b/drivers/media/usb/em28xx/em28xx-cards.c > >> @@ -4095,6 +4095,8 @@ static int em28xx_usb_probe(struct usb_interface *intf, > >> */ > >> #ifdef CONFIG_MEDIA_CONTROLLER > >> retval = media_device_register(dev->media_dev); > >> + if (retval) > >> + goto err_free; > > > > Not freeing resources here is intentional. See, the media controller > > API is optional on this driver. It will just provide a way to identify > > the device's topology, but the device is completely usable without > > it. > > > > Perhaps we need, instead, a patch documenting it, and preventing > > static analysis tools to point it as an issue. > > > > Thanks, > > Mauro > > Thank you for your feedback, however I had a few questions... > > While I understand what you mean about optional nature of media > controller registration in this case, a quick glance into other calls to > media_device_register() across the source code shows that usually > failure with registering is handled as a proper error regardless of > whether the device is still usable. But if you think that we can make an > exception here, I'll happily oblige. It depends on how the actual device is controlled. "Normal" media devices are fully controlled via v4l2 API. On those, the media controller API is there just to let userspace to query about the internal settings, but the actual pipelines are created via V4L2 API. Almost all normal applications will just ignore the media controller API. Embedded hardware, however, require setting pipelines via media controller for they to actually work. Almost all drivers implementing the media controller API fall on this category. > > Then if I am to continue on this path, would the following comment above > the call to media_device_register() suffice? > > #ifdef CONFIG_MEDIA_CONTROLLER > + /* > + * No need to check the return value, the device will still be + > * usable without media controller API. > + */ > retval = media_device_register(dev->media_dev); That works for me. It would still produce alerts at static analyzers, as they'll notice that we're storing retval there without actually using it. Thanks, Mauro