Message ID | 8a7607f8-d634-415e-8269-e26dcc0f9fdc@web.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-89433-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp434354dyc; Sat, 2 Mar 2024 03:42:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXRI8SHlQKr45A967oQA4KQVpUS4nt3RbjYcvbk8z48oBa2GObagIyk4Mo9rfmaIhkWohMibByqVKih9MVj081VaFvg+w== X-Google-Smtp-Source: AGHT+IFVAohuddTtHmAobve/p3DBxHNiuc+GQ1jQXOMUIqnQGVbjv9zpGQcCgxxZlHmZrbGn2oVd X-Received: by 2002:a05:620a:1265:b0:787:fab0:db2a with SMTP id b5-20020a05620a126500b00787fab0db2amr4561763qkl.10.1709379776045; Sat, 02 Mar 2024 03:42:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709379776; cv=pass; d=google.com; s=arc-20160816; b=oMS6FOURw1S0thOyH2syXz/hULqgy6sknlhsVi3D2PCXiFgQgmeye1ltLTFNwzcQuV OQRg2wdNYHWl7GecIO/VW4YxWEZ0GLD5cfkGlDy35T6JQB865uRbfssWScqCM7UK8CYy 1VYmw1r3nw5Ajz3sW6CrsWWs9wwy/2ByJRpH6wgplqkHBwVtv16VuLucsKhzaVfeGXbQ UiYWxXu0AW2nPa45ePP/X5ZCvCn1POYzpBZTti9DjEy6Usy8Wf/4s5zvYfMn7Y0UdXD4 n4k3zBC6CMlP7d3cZeK23gxBC8jHtkDerzFzxdzME/41Tsk74gIfgQCF7MWT6xUEMXN3 B9DQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:subject:from:cc :content-language:to:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=F3+Zr4RNz2HB2buZrXbiMqi7B+BH82nQt4WgMoMn4uo=; fh=gdG+9KoEtVobYFXm4FQj2dH7C8QFmwpeP9yG/fQISYg=; b=go7R0dCd7SBaD0xEocsC9mdyB0HtNXfC0NaRS8K96xAsdowdY9Un1B0FZC24LQGBE3 jt16TpXynzEOwu66Thg6PburwMqn+ORC2nNxxsoIvLoRiUiwQGHyn6Hgz+VGahcIe6jv Y8tbXtOoNq0r0G31Ko25bl1ZIDwRIgJKHHB/f63H85lzBqaeo/EgFgFSlEbq+BdEpjeR NWQEuXzaCNtTcZUGIXbZBF8WMGPgPjjX1EovmzHTTZoHZBIRUtAgmZqH8EJmH6Oc76s4 7656wgppkCLWkYQsL/6gzl4JqqT+YNlc2BSKjRCFX1hJRWF7Kj/PXiJ7jPo7qyQn7sVU sdpA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=DPXjRX1d; arc=pass (i=1 spf=pass spfdomain=web.de dkim=pass dkdomain=web.de dmarc=pass fromdomain=web.de); spf=pass (google.com: domain of linux-kernel+bounces-89433-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89433-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id az38-20020a05620a172600b00788058a2314si3975000qkb.729.2024.03.02.03.42.55 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Mar 2024 03:42:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89433-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=DPXjRX1d; arc=pass (i=1 spf=pass spfdomain=web.de dkim=pass dkdomain=web.de dmarc=pass fromdomain=web.de); spf=pass (google.com: domain of linux-kernel+bounces-89433-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89433-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D231E1C218E6 for <ouuuleilei@gmail.com>; Sat, 2 Mar 2024 11:42:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F088617994; Sat, 2 Mar 2024 11:42:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="DPXjRX1d" Received: from mout.web.de (mout.web.de [212.227.17.12]) (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 25642376; Sat, 2 Mar 2024 11:42:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709379756; cv=none; b=A1Ih5EXtV+5oCBT2Utt9nQDmJopnVKh4R5BWW40WxOvKihgV+j3IwXr22B8o1BlmVQiiadqXgLOmeCAuIZRI8X1I+VmHjsZ7aM6rmuenBX/k6o88XLjE7DP6/G4Ns64iMp3sSJJNXZwGZFLBq3GI6zdRvtqajfhW3mCwO2klkXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709379756; c=relaxed/simple; bh=E3Q9qWL8O0+GN7VCd1Dl19Fyi0SNZTTCX+IlfgtclCY=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=q8EU+MrbzLAF/bux9mi22Nqx6+kNUwE8Dc/8ivstopf9SkA4yb4jp0KcJK7eubupm3KtTuxIBXGbgHS1Rrli0ss1pExATY/zqWvHH4ZLAh9EqHzy8MYWBb7I0K8FtpFCsos3MIIJ4lwzSjPt3EBOAzqQ0CciXebiLV9fadKLi8o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b=DPXjRX1d; arc=none smtp.client-ip=212.227.17.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1709379729; x=1709984529; i=markus.elfring@web.de; bh=E3Q9qWL8O0+GN7VCd1Dl19Fyi0SNZTTCX+IlfgtclCY=; h=X-UI-Sender-Class:Date:To:Cc:From:Subject; b=DPXjRX1d6w9S6Wi3Yvg/FUZrL14SO1FScXJSOxyDgch1YbvYXMK+Tkwz0voKtzSa XydXNk9qno9veQye0HBtEdDw1EhNudQh2HvHJLA7iSsWeZXzMThBSYcHf4brt4zLY mdwzDp0Y1bB/XG/eCv/nZt3OLvQfcxy6sxYO+IJaQOx4J9BS0EDajim9g+/lMZvBT CeFt9w8yUALALMCVlccluCb9wlfvWrjgFIvXJgQg8CDbPfvhHllFaQ0pkyBRcCIJI jIX1XnYWoWsIWCBDKWysBiHLjD0RFzRjhK4J3rrf9zWJ0JpbnRYS/FCsP9zG2RW+Z Bl6VjOSA9m3uyj/9iA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.86.95]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MActe-1rZpFp2G88-00BXXz; Sat, 02 Mar 2024 12:42:09 +0100 Message-ID: <8a7607f8-d634-415e-8269-e26dcc0f9fdc@web.de> Date: Sat, 2 Mar 2024 12:42:08 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: linux-input@vger.kernel.org, kernel-janitors@vger.kernel.org, Dmitry Torokhov <dmitry.torokhov@gmail.com>, Jeff LaBundy <jeff@labundy.com>, Rob Herring <robh@kernel.org>, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de> Content-Language: en-GB Cc: LKML <linux-kernel@vger.kernel.org> From: Markus Elfring <Markus.Elfring@web.de> Subject: [PATCH] Input: iqs626a - Use common error handling code in iqs626_parse_events() Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:h9A/1MY03Hlt1owaa+huYDBVzhk7qF1ZdtK174hH1eiFGxapT2y Pw/pNtsWPNsatHBRwAxOvnvQXDIFIbs0sVAa1uSBSJSTL10AUeqHlv0e9mJoqgcz0kBHfay H48J2/sMmnVgXmXl6ryZH1OlUJBSJpuCfyKZjGYRQ9CpWRgVKvSBXJXIAqoBnn15TMoBHxx 7Fq2+BvxeC5/aIgp54OLg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:pmsEEA7ll84=;dN/IpDwWFntwUoLhARGcxU797SD Zg1a1k0c7eO4VMzGtV6DrBvjwBqb5YJlqjVVZn0jaEzgtGg3WVKhb1RbLuF7n+xyZYsl8gFny 1Jay2eQlONetdD+M0SF6SmVZQMj4LRCEMQ4lgOI+idzT9mLy62Rog5h4BoG6vBVD46Nx7Xv+J CrQjLq0ktWL6/lLhPNv1REL+H6z/I+XrFJ1Cfm/t2HhK0b97TFBnod97va3t3f4GYw9iHNtxn 3qRl2VYU6m/K1eO3LtjPN47q2sEmKNOwRdYp5dczOCMNd/Wv7bn6nNQEYwxaduDMVS1oH49Tv Z60b7zH7wVtt1rlzMj5uVrTq9mCdGBHnTCqGj8+Z9nwoCsQ7nyXmnWrN1RCY4OjD9yZeja5Cw 5PXKsTMkqq/Mhu/KpZ8WaH2kSUeoOje7x0j4w5q/FheRuNwe2L9+Z9VB3EJoAn5mXWR9VxUaE E23bQsqFtXZG9YUqPCk1HnbiJpioQRB5P8S7mzHcHnXLhEFHlUmwhMX1twxW7DZ0pjWx6W7Vf wy2xlLkpA/96MrqT2Bx8JZ8nAQtaQ8D/2HTiK3w1dG0kLaJQudQtD0ea/kAGFkwE28Rnrh/SU ImuYUlUBSk+GwypHnP9rAtjsqkF2COh7oZtrHxS7YR1ZbfL6VCIWfRC7llkFne7t0i6hZmouo 5+Yo0AyO/yHU2ojsqJG+yGnmT00dzLmTgQUg7ZoRygrheL3FF0Zl9wVPtWGGWCbFFYyqKEmua GXp37jTM8x3aRTE/gr+v16PdOaGp3ZjVXXsWJPOL87oafeNAHL3aOlLXieoi6BsAKvMGXvaI6 oez+RcDVLbOJAyDCTtT3Ed5feWOFn19BdTDbWySRDGNoo= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792414608332943142 X-GMAIL-MSGID: 1792414608332943142 |
Series |
Input: iqs626a - Use common error handling code in iqs626_parse_events()
|
|
Commit Message
Markus Elfring
March 2, 2024, 11:42 a.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net> Date: Sat, 2 Mar 2024 11:44:17 +0100 Add a jump target so that a bit of exception handling can be better reused at the end of this function implementation. This issue was transformed by using the Coccinelle software. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- drivers/input/misc/iqs626a.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) -- 2.44.0
Comments
Hi Markus, On Sat, Mar 02, 2024 at 12:42:08PM +0100, Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 2 Mar 2024 11:44:17 +0100 > > Add a jump target so that a bit of exception handling can be better reused > at the end of this function implementation. > > This issue was transformed by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/input/misc/iqs626a.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/drivers/input/misc/iqs626a.c b/drivers/input/misc/iqs626a.c > index 0dab54d3a060..fa9570755f7b 100644 > --- a/drivers/input/misc/iqs626a.c > +++ b/drivers/input/misc/iqs626a.c > @@ -530,8 +530,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, > dev_err(&client->dev, > "Invalid input type: %u\n", > val); > - fwnode_handle_put(ev_node); > - return -EINVAL; > + goto put_fwnode; > } > > iqs626->kp_type[ch_id][i] = val; > @@ -545,8 +544,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, > dev_err(&client->dev, > "Invalid %s channel hysteresis: %u\n", > fwnode_get_name(ch_node), val); > - fwnode_handle_put(ev_node); > - return -EINVAL; > + goto put_fwnode; > } > > if (i == IQS626_EVENT_DEEP_DN || > @@ -566,8 +564,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, > dev_err(&client->dev, > "Invalid %s channel threshold: %u\n", > fwnode_get_name(ch_node), val); > - fwnode_handle_put(ev_node); > - return -EINVAL; > + goto put_fwnode; > } > > if (ch_id == IQS626_CH_HALL) > @@ -580,6 +577,10 @@ iqs626_parse_events(struct iqs626_private *iqs626, > } > > return 0; > + > +put_fwnode: > + fwnode_handle_put(ev_node); > + return -EINVAL; > } > > static noinline_for_stack int > -- > 2.44.0 > Thank you for this patch, but it seems like a NAK to me. I think this is a matter of personal preference, and according to mine, it is much more confusing to insert a goto label after a function's primary return path than to have 2-3 calls to fwnode_handle_put(). If you feel strongly otherwise, then I would suggest a helper function as recommended by Dmitry in another thread. However, maybe that helper should live in the driver core, as I suspect this driver is not the only place we can avoid calling fwnode_handle_put() in an error path that returns an int. Kind regards, Jeff LaBundy
On Sun, Mar 03, 2024 at 09:12:16PM -0600, Jeff LaBundy wrote: > Hi Markus, > > On Sat, Mar 02, 2024 at 12:42:08PM +0100, Markus Elfring wrote: > > From: Markus Elfring <elfring@users.sourceforge.net> > > Date: Sat, 2 Mar 2024 11:44:17 +0100 > > > > Add a jump target so that a bit of exception handling can be better reused > > at the end of this function implementation. > > > > This issue was transformed by using the Coccinelle software. > > > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > > --- > > drivers/input/misc/iqs626a.c | 13 +++++++------ > > 1 file changed, 7 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/input/misc/iqs626a.c b/drivers/input/misc/iqs626a.c > > index 0dab54d3a060..fa9570755f7b 100644 > > --- a/drivers/input/misc/iqs626a.c > > +++ b/drivers/input/misc/iqs626a.c > > @@ -530,8 +530,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, > > dev_err(&client->dev, > > "Invalid input type: %u\n", > > val); > > - fwnode_handle_put(ev_node); > > - return -EINVAL; > > + goto put_fwnode; > > } > > > > iqs626->kp_type[ch_id][i] = val; > > @@ -545,8 +544,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, > > dev_err(&client->dev, > > "Invalid %s channel hysteresis: %u\n", > > fwnode_get_name(ch_node), val); > > - fwnode_handle_put(ev_node); > > - return -EINVAL; > > + goto put_fwnode; > > } > > > > if (i == IQS626_EVENT_DEEP_DN || > > @@ -566,8 +564,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, > > dev_err(&client->dev, > > "Invalid %s channel threshold: %u\n", > > fwnode_get_name(ch_node), val); > > - fwnode_handle_put(ev_node); > > - return -EINVAL; > > + goto put_fwnode; > > } > > > > if (ch_id == IQS626_CH_HALL) > > @@ -580,6 +577,10 @@ iqs626_parse_events(struct iqs626_private *iqs626, > > } > > > > return 0; > > + > > +put_fwnode: > > + fwnode_handle_put(ev_node); > > + return -EINVAL; > > } > > > > static noinline_for_stack int > > -- > > 2.44.0 > > > > Thank you for this patch, but it seems like a NAK to me. I think this is > a matter of personal preference, and according to mine, it is much more > confusing to insert a goto label after a function's primary return path > than to have 2-3 calls to fwnode_handle_put(). > > If you feel strongly otherwise, then I would suggest a helper function as > recommended by Dmitry in another thread. However, maybe that helper should > live in the driver core, as I suspect this driver is not the only place we > can avoid calling fwnode_handle_put() in an error path that returns an int. Yes, it should go into include/linux/fwnode.h, something like DEFINE_FREE(fwnode, struct fwnode_handle *, if (_T) fwnode_hanlde_put(_T)); Then drivers can do: struct fwnode_handle *ev_node __free(fwnode) = fwnode_get_named_child_node(ch_node, ev_name); and have it automatically be "put" once execution leaves the variable scope. Ah, we actually already have it defined in include/linux/property.h, all the better. Thanks.
On Sun, Mar 03, 2024 at 08:29:49PM -0800, Dmitry Torokhov wrote: > On Sun, Mar 03, 2024 at 09:12:16PM -0600, Jeff LaBundy wrote: > > Hi Markus, > > > > On Sat, Mar 02, 2024 at 12:42:08PM +0100, Markus Elfring wrote: > > > From: Markus Elfring <elfring@users.sourceforge.net> > > > Date: Sat, 2 Mar 2024 11:44:17 +0100 > > > > > > Add a jump target so that a bit of exception handling can be better reused > > > at the end of this function implementation. > > > > > > This issue was transformed by using the Coccinelle software. > > > > > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > > > --- > > > drivers/input/misc/iqs626a.c | 13 +++++++------ > > > 1 file changed, 7 insertions(+), 6 deletions(-) > > > > > > diff --git a/drivers/input/misc/iqs626a.c b/drivers/input/misc/iqs626a.c > > > index 0dab54d3a060..fa9570755f7b 100644 > > > --- a/drivers/input/misc/iqs626a.c > > > +++ b/drivers/input/misc/iqs626a.c > > > @@ -530,8 +530,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, > > > dev_err(&client->dev, > > > "Invalid input type: %u\n", > > > val); > > > - fwnode_handle_put(ev_node); > > > - return -EINVAL; > > > + goto put_fwnode; > > > } > > > > > > iqs626->kp_type[ch_id][i] = val; > > > @@ -545,8 +544,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, > > > dev_err(&client->dev, > > > "Invalid %s channel hysteresis: %u\n", > > > fwnode_get_name(ch_node), val); > > > - fwnode_handle_put(ev_node); > > > - return -EINVAL; > > > + goto put_fwnode; > > > } > > > > > > if (i == IQS626_EVENT_DEEP_DN || > > > @@ -566,8 +564,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, > > > dev_err(&client->dev, > > > "Invalid %s channel threshold: %u\n", > > > fwnode_get_name(ch_node), val); > > > - fwnode_handle_put(ev_node); > > > - return -EINVAL; > > > + goto put_fwnode; > > > } > > > > > > if (ch_id == IQS626_CH_HALL) > > > @@ -580,6 +577,10 @@ iqs626_parse_events(struct iqs626_private *iqs626, > > > } > > > > > > return 0; > > > + > > > +put_fwnode: > > > + fwnode_handle_put(ev_node); > > > + return -EINVAL; > > > } > > > > > > static noinline_for_stack int > > > -- > > > 2.44.0 > > > > > > > Thank you for this patch, but it seems like a NAK to me. I think this is > > a matter of personal preference, and according to mine, it is much more > > confusing to insert a goto label after a function's primary return path > > than to have 2-3 calls to fwnode_handle_put(). > > > > If you feel strongly otherwise, then I would suggest a helper function as > > recommended by Dmitry in another thread. However, maybe that helper should > > live in the driver core, as I suspect this driver is not the only place we > > can avoid calling fwnode_handle_put() in an error path that returns an int. > > Yes, it should go into include/linux/fwnode.h, something like > > DEFINE_FREE(fwnode, struct fwnode_handle *, if (_T) fwnode_hanlde_put(_T)); > > Then drivers can do: > > struct fwnode_handle *ev_node __free(fwnode) = > fwnode_get_named_child_node(ch_node, ev_name); > > and have it automatically be "put" once execution leaves the variable > scope. > > Ah, we actually already have it defined in include/linux/property.h, all > the better. It's already there. DEFINE_FREE(fwnode_handle, struct fwnode_handle *, fwnode_handle_put(_T)) I can send a patch for this. You need to be a bit carefull to move the declaration into the correct scope for this to work. I should write some Smatch rules for this... regards, dan carpenter
On Mon, 4 Mar 2024, Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Mon, 4 Mar 2024 11:40:04 +0100 > > Scope-based resource management became supported also for this software > area by contributions of Jonathan Cameron on 2024-02-17. > > device property: Add cleanup.h based fwnode_handle_put() scope based cleanup. > https://lore.kernel.org/r/20240217164249.921878-3-jic23@kernel.org > > > * Thus use the attribute “__free(fwnode_handle)”. > > * Reduce the scope for the local variable “ev_node” into a for loop. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > > v2: > An other cleanup technique was applied as requested by Dmitry Torokhov > and Jeff LaBundy. > > > drivers/input/misc/iqs626a.c | 8 ++------ > 1 file changed, 2 insertions(+), 6 deletions(-) > > diff --git a/drivers/input/misc/iqs626a.c b/drivers/input/misc/iqs626a.c > index 0dab54d3a060..86fcb5134f45 100644 > --- a/drivers/input/misc/iqs626a.c > +++ b/drivers/input/misc/iqs626a.c > @@ -462,7 +462,6 @@ iqs626_parse_events(struct iqs626_private *iqs626, > { > struct iqs626_sys_reg *sys_reg = &iqs626->sys_reg; > struct i2c_client *client = iqs626->client; > - struct fwnode_handle *ev_node; > const char *ev_name; > u8 *thresh, *hyst; > unsigned int val; > @@ -501,6 +500,8 @@ iqs626_parse_events(struct iqs626_private *iqs626, > if (!iqs626_channels[ch_id].events[i]) > continue; > > + struct fwnode_handle *ev_node __free(fwnode_handle); Doesn't this need to be initialized? julia > + > if (ch_id == IQS626_CH_TP_2 || ch_id == IQS626_CH_TP_3) { > /* > * Trackpad touch events are simply described under the > @@ -530,7 +531,6 @@ iqs626_parse_events(struct iqs626_private *iqs626, > dev_err(&client->dev, > "Invalid input type: %u\n", > val); > - fwnode_handle_put(ev_node); > return -EINVAL; > } > > @@ -545,7 +545,6 @@ iqs626_parse_events(struct iqs626_private *iqs626, > dev_err(&client->dev, > "Invalid %s channel hysteresis: %u\n", > fwnode_get_name(ch_node), val); > - fwnode_handle_put(ev_node); > return -EINVAL; > } > > @@ -566,7 +565,6 @@ iqs626_parse_events(struct iqs626_private *iqs626, > dev_err(&client->dev, > "Invalid %s channel threshold: %u\n", > fwnode_get_name(ch_node), val); > - fwnode_handle_put(ev_node); > return -EINVAL; > } > > @@ -575,8 +573,6 @@ iqs626_parse_events(struct iqs626_private *iqs626, > else > *(thresh + iqs626_events[i].th_offs) = val; > } > - > - fwnode_handle_put(ev_node); > } > > return 0; > -- > 2.44.0 > > >
On Mon, Mar 04, 2024 at 11:55:23AM +0100, Julia Lawall wrote: > > > On Mon, 4 Mar 2024, Markus Elfring wrote: > > > From: Markus Elfring <elfring@users.sourceforge.net> > > Date: Mon, 4 Mar 2024 11:40:04 +0100 > > > > Scope-based resource management became supported also for this software > > area by contributions of Jonathan Cameron on 2024-02-17. > > > > device property: Add cleanup.h based fwnode_handle_put() scope based cleanup. > > https://lore.kernel.org/r/20240217164249.921878-3-jic23@kernel.org > > > > > > * Thus use the attribute “__free(fwnode_handle)”. > > > > * Reduce the scope for the local variable “ev_node” into a for loop. > > > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > > --- > > > > v2: > > An other cleanup technique was applied as requested by Dmitry Torokhov > > and Jeff LaBundy. > > > > > > drivers/input/misc/iqs626a.c | 8 ++------ > > 1 file changed, 2 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/input/misc/iqs626a.c b/drivers/input/misc/iqs626a.c > > index 0dab54d3a060..86fcb5134f45 100644 > > --- a/drivers/input/misc/iqs626a.c > > +++ b/drivers/input/misc/iqs626a.c > > @@ -462,7 +462,6 @@ iqs626_parse_events(struct iqs626_private *iqs626, > > { > > struct iqs626_sys_reg *sys_reg = &iqs626->sys_reg; > > struct i2c_client *client = iqs626->client; > > - struct fwnode_handle *ev_node; > > const char *ev_name; > > u8 *thresh, *hyst; > > unsigned int val; > > @@ -501,6 +500,8 @@ iqs626_parse_events(struct iqs626_private *iqs626, > > if (!iqs626_channels[ch_id].events[i]) > > continue; > > > > + struct fwnode_handle *ev_node __free(fwnode_handle); > > Doesn't this need to be initialized? > Only if you declared before the continue; statement. Generally kernel style is that you have to declare variables at the start of the block... But that's becoming less universal now that it's not a compile error. regards, dan carpenter
> DEFINE_FREE(fwnode_handle, struct fwnode_handle *, fwnode_handle_put(_T)) > > I can send a patch for this. You need to be a bit carefull to move > the declaration into the correct scope for this to work. I should write > some Smatch rules for this... I became also curious how available development tools will evolve further for improved handling of scope-based resource management. Regards, Markus
diff --git a/drivers/input/misc/iqs626a.c b/drivers/input/misc/iqs626a.c index 0dab54d3a060..fa9570755f7b 100644 --- a/drivers/input/misc/iqs626a.c +++ b/drivers/input/misc/iqs626a.c @@ -530,8 +530,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, dev_err(&client->dev, "Invalid input type: %u\n", val); - fwnode_handle_put(ev_node); - return -EINVAL; + goto put_fwnode; } iqs626->kp_type[ch_id][i] = val; @@ -545,8 +544,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, dev_err(&client->dev, "Invalid %s channel hysteresis: %u\n", fwnode_get_name(ch_node), val); - fwnode_handle_put(ev_node); - return -EINVAL; + goto put_fwnode; } if (i == IQS626_EVENT_DEEP_DN || @@ -566,8 +564,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, dev_err(&client->dev, "Invalid %s channel threshold: %u\n", fwnode_get_name(ch_node), val); - fwnode_handle_put(ev_node); - return -EINVAL; + goto put_fwnode; } if (ch_id == IQS626_CH_HALL) @@ -580,6 +577,10 @@ iqs626_parse_events(struct iqs626_private *iqs626, } return 0; + +put_fwnode: + fwnode_handle_put(ev_node); + return -EINVAL; } static noinline_for_stack int