devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff LaBundy <jeff@labundy.com>
To: dmitry.torokhov@gmail.com, robh+dt@kernel.org
Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	Jeff LaBundy <jeff@labundy.com>
Subject: [PATCH 02/11] Input: iqs7222 - report malformed properties
Date: Thu,  8 Sep 2022 08:15:39 -0500	[thread overview]
Message-ID: <20220908131548.48120-3-jeff@labundy.com> (raw)
In-Reply-To: <20220908131548.48120-1-jeff@labundy.com>

Nonzero return values of several calls to fwnode_property_read_u32()
are silenty ignored, leaving no way to know that the properties were
not applied in the event of an error.

To solve this problem, follow the design pattern used throughout the
rest of the driver by first checking if the property is present, and
then evaluating the return value of fwnode_property_read_u32().

Fixes: e505edaedcb9 ("Input: add support for Azoteq IQS7222A/B/C")
Signed-off-by: Jeff LaBundy <jeff@labundy.com>
---
 drivers/input/misc/iqs7222.c | 65 ++++++++++++++++++++++++++++++------
 1 file changed, 55 insertions(+), 10 deletions(-)

diff --git a/drivers/input/misc/iqs7222.c b/drivers/input/misc/iqs7222.c
index 04c1050d845c..fdade24caa8a 100644
--- a/drivers/input/misc/iqs7222.c
+++ b/drivers/input/misc/iqs7222.c
@@ -1819,8 +1819,17 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, int chan_index)
 		chan_setup[0] |= IQS7222_CHAN_SETUP_0_REF_MODE_FOLLOW;
 		chan_setup[4] = val * 42 + 1048;
 
-		if (!fwnode_property_read_u32(chan_node, "azoteq,ref-weight",
-					      &val)) {
+		if (fwnode_property_present(chan_node, "azoteq,ref-weight")) {
+			error = fwnode_property_read_u32(chan_node,
+							 "azoteq,ref-weight",
+							 &val);
+			if (error) {
+				dev_err(&client->dev,
+					"Failed to read %s reference weight: %d\n",
+					fwnode_get_name(chan_node), error);
+				goto put_chan_node;
+			}
+
 			if (val > U16_MAX) {
 				dev_err(&client->dev,
 					"Invalid %s reference weight: %u\n",
@@ -1921,9 +1930,8 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, int chan_index)
 			goto put_chan_node;
 		}
 
-		if (!fwnode_property_read_u32(event_node,
-					      "azoteq,timeout-press-ms",
-					      &val)) {
+		if (fwnode_property_present(event_node,
+					    "azoteq,timeout-press-ms")) {
 			/*
 			 * The IQS7222B employs a global pair of press timeout
 			 * registers as opposed to channel-specific registers.
@@ -1933,6 +1941,17 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, int chan_index)
 				     &iqs7222->btn_setup[chan_index][2] :
 				     &sys_setup[9];
 
+			error = fwnode_property_read_u32(event_node,
+							 "azoteq,timeout-press-ms",
+							 &val);
+			if (error) {
+				dev_err(&client->dev,
+					"Failed to read %s press timeout: %d\n",
+					fwnode_get_name(chan_node), error);
+				fwnode_handle_put(event_node);
+				goto put_chan_node;
+			}
+
 			if (val > U8_MAX * 500) {
 				dev_err(&client->dev,
 					"Invalid %s press timeout: %u\n",
@@ -2098,7 +2117,15 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
 	if (fwnode_property_present(sldr_node, "azoteq,use-prox"))
 		sldr_setup[4 + reg_offset] -= 2;
 
-	if (!fwnode_property_read_u32(sldr_node, "azoteq,slider-size", &val)) {
+	if (fwnode_property_present(sldr_node, "azoteq,slider-size")) {
+		error = fwnode_property_read_u32(sldr_node,
+						 "azoteq,slider-size", &val);
+		if (error) {
+			dev_err(&client->dev, "Failed to read %s size: %d\n",
+				fwnode_get_name(sldr_node), error);
+			goto put_sldr_node;
+		}
+
 		if (!val || val > dev_desc->sldr_res) {
 			dev_err(&client->dev, "Invalid %s size: %u\n",
 				fwnode_get_name(sldr_node), val);
@@ -2115,7 +2142,16 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
 		}
 	}
 
-	if (!fwnode_property_read_u32(sldr_node, "azoteq,top-speed", &val)) {
+	if (fwnode_property_present(sldr_node, "azoteq,top-speed")) {
+		error = fwnode_property_read_u32(sldr_node,
+						 "azoteq,top-speed", &val);
+		if (error) {
+			dev_err(&client->dev,
+				"Failed to read %s top speed: %d\n",
+				fwnode_get_name(sldr_node), error);
+			goto put_sldr_node;
+		}
+
 		if (val > (reg_offset ? U16_MAX : U8_MAX * 4)) {
 			dev_err(&client->dev, "Invalid %s top speed: %u\n",
 				fwnode_get_name(sldr_node), val);
@@ -2131,10 +2167,19 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
 		}
 	}
 
-	if (!fwnode_property_read_u32(sldr_node, "linux,axis", &val)) {
-		u16 sldr_max = sldr_setup[3] - 1;
+	if (fwnode_property_present(sldr_node, "linux,axis")) {
+		u16 sldr_max;
+
+		error = fwnode_property_read_u32(sldr_node, "linux,axis", &val);
+		if (error) {
+			dev_err(&client->dev, "Failed to read %s axis: %d\n",
+				fwnode_get_name(sldr_node), error);
+			goto put_sldr_node;
+		}
 
-		if (!reg_offset) {
+		if (reg_offset) {
+			sldr_max = sldr_setup[3] - 1;
+		} else {
 			sldr_max = sldr_setup[2];
 
 			sldr_max &= IQS7222_SLDR_SETUP_2_RES_MASK;
-- 
2.25.1


  parent reply	other threads:[~2022-09-08 13:17 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-08 13:15 [PATCH 00/11] Additional fixes for Azoteq IQS7222A/B/C Jeff LaBundy
2022-09-08 13:15 ` [PATCH 01/11] Input: iqs7222 - drop unused device node references Jeff LaBundy
2022-09-08 21:17   ` Dmitry Torokhov
2022-09-09  2:04     ` Jeff LaBundy
2022-09-09  4:37       ` Dmitry Torokhov
2022-09-10  0:00         ` Jeff LaBundy
2022-09-08 13:15 ` Jeff LaBundy [this message]
2022-09-08 21:21   ` [PATCH 02/11] Input: iqs7222 - report malformed properties Dmitry Torokhov
2022-09-09  2:08     ` Jeff LaBundy
2022-09-09  4:42       ` Dmitry Torokhov
2022-09-10  0:04         ` Jeff LaBundy
2022-09-08 13:15 ` [PATCH 03/11] dt-bindings: input: iqs7222: Correct minimum slider size Jeff LaBundy
2022-09-13 11:37   ` Rob Herring
2022-09-08 13:15 ` [PATCH 04/11] Input: iqs7222 - protect against undefined " Jeff LaBundy
2022-09-08 13:15 ` [PATCH 05/11] Input: iqs7222 - trim force communication command Jeff LaBundy
2022-09-08 21:24   ` Dmitry Torokhov
2022-09-13 21:24     ` Jeff LaBundy
2022-09-14 10:10       ` Dmitry Torokhov
2022-09-08 13:15 ` [PATCH 06/11] Input: iqs7222 - avoid sending empty SYN_REPORT events Jeff LaBundy
2022-09-14 10:10   ` Dmitry Torokhov
2022-09-08 13:15 ` [PATCH 07/11] Input: iqs7222 - set all ULP entry masks by default Jeff LaBundy
2022-09-14 10:10   ` Dmitry Torokhov
2022-09-08 13:15 ` [PATCH 08/11] Input: iqs7222 - allow 'linux,code' to be optional Jeff LaBundy
2022-09-08 13:15 ` [PATCH 09/11] dt-bindings: input: iqs7222: Allow " Jeff LaBundy
2022-09-13 11:42   ` Rob Herring
2022-09-13 13:47     ` Jeff LaBundy
2022-09-08 13:15 ` [PATCH 10/11] dt-bindings: input: iqs7222: Add support for IQS7222A v1.13+ Jeff LaBundy
2022-09-13 11:44   ` Rob Herring
2022-09-08 13:15 ` [PATCH 11/11] Input: iqs7222 - add " Jeff LaBundy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220908131548.48120-3-jeff@labundy.com \
    --to=jeff@labundy.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).