Skip to contentSkip to conversation

gpio: Fix wrong pointer type in pca953x

PATCH Superseded Dirk Eibach 3 participants 6 messages Feb 22, 2011 – Feb 24, 2011 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: Fix wrong pointer type in pca953x

pca953x_get_alt_pdata() uses uint16_t* as result type for of_get_property(), but numeric of values are u32.

---
 drivers/gpio/pca953x.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/gpio/pca953x.c +1 -1
index a261972..d79e031 100644
@@ -448,7 +448,7 @@ pca953x_get_alt_pdata(struct i2c_client *client)
 {
 	struct pca953x_platform_data *pdata;
 	struct device_node *node;
-	const uint16_t *val;
+	const u32 *val;
 
 	node = client->dev.of_node;
 	if (node == NULL)
Signature · 1 line
1.5.6.5
#1 lore raw

drivers/gpio/pca953x.c pca953x_get_alt_pdata(struct i2c_client *client) · line 451

Quoted 5 lines · Dirk Eibach
drivers/gpio/pca953x.c +1 -1
 	struct pca953x_platform_data *pdata;
 	struct device_node *node;
-	const uint16_t *val;
+	const u32 *val;

This should probably be signed? We compare it against zero later on.

                if (*val < 0)
                        dev_warn(&client->dev,
                                 "invalid gpio-base in device tree\n");

regards,
dan carpenter

#2 lore raw
Quoted 10 lines

drivers/gpio/pca953x.c pca953x_get_alt_pdata(struct i2c_client *client) · line 451

Quoted 7 lines
drivers/gpio/pca953x.c +1 -1
 	struct pca953x_platform_data *pdata;
 	struct device_node *node;
-	const uint16_t *val;
+	const u32 *val;

This should probably be signed? We compare it against zero later on.

Quoted 4 lines
                if (*val < 0)
                        dev_warn(&client->dev,
                                 "invalid gpio-base in device 

tree\n");

Good catch.
of property values are generally unsigned. The whole check is bogus here. Will supply updated patch later.

Quoted 2 lines

regards,
dan carpenter

Cheers
Dirk

#3 lore raw

PATCH v2 1/1 gpio: Fix wrong pointer type in pca953x

In reply to Dan Carpenter

pca953x_get_alt_pdata() uses uint16_t* as result type for of_get_property(), but numeric of values are u32.

Checking for negative values is bogus because of-property values are unsigned by definition.

---
Changes since v1:
- removed bogus check for negative property values

 drivers/gpio/pca953x.c |   11 +++--------
 1 files changed, 3 insertions(+), 8 deletions(-)
drivers/gpio/pca953x.c +3 -8
index a261972..8acbfe9 100644
@@ -448,7 +448,7 @@ pca953x_get_alt_pdata(struct i2c_client *client)
 {
 	struct pca953x_platform_data *pdata;
 	struct device_node *node;
-	const uint16_t *val;
+	const u32 *val;
 
 	node = client->dev.of_node;
 	if (node == NULL)
@@ -462,13 +462,8 @@ pca953x_get_alt_pdata(struct i2c_client *client)
 
 	pdata->gpio_base = -1;
 	val = of_get_property(node, "linux,gpio-base", NULL);
-	if (val) {
-		if (*val < 0)
-			dev_warn(&client->dev,
-				 "invalid gpio-base in device tree\n");
-		else
-			pdata->gpio_base = *val;
-	}
+	if (val)
+		pdata->gpio_base = *val;
 
 	val = of_get_property(node, "polarity", NULL);
 	if (val)
Signature · 1 line
1.5.6.5
#4 lore raw

PATCH v3 1/1 gpio: Fix wrong pointer type in pca953x

In reply to Dan Carpenter

pca953x_get_alt_pdata() uses uint16_t* as result type for of_get_property(), but numeric of values are __be32.

Checking for negative values is bogus because of-property values are unsigned by definition.
Instead check for proper property size.

---
Changes since v1:
- removed bogus check for negative property values

Changes since v2:
- assume big-endian properties
- check property size

 drivers/gpio/pca953x.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
drivers/gpio/pca953x.c +7 -6
index a261972..694b0f9 100644
@@ -448,7 +448,8 @@ pca953x_get_alt_pdata(struct i2c_client *client)
 {
 	struct pca953x_platform_data *pdata;
 	struct device_node *node;
-	const uint16_t *val;
+	const __be32 *val;
+	int size;
 
 	node = client->dev.of_node;
 	if (node == NULL)
@@ -461,13 +462,13 @@ pca953x_get_alt_pdata(struct i2c_client *client)
 	}
 
 	pdata->gpio_base = -1;
-	val = of_get_property(node, "linux,gpio-base", NULL);
+	val = of_get_property(node, "linux,gpio-base", &size);
 	if (val) {
-		if (*val < 0)
-			dev_warn(&client->dev,
-				 "invalid gpio-base in device tree\n");
+		if (size != sizeof(*val))
+			dev_warn(&client->dev, "%s: wrong linux,gpio-base\n",
+				 node->full_name);
 		else
-			pdata->gpio_base = *val;
+			pdata->gpio_base = be32_to_cpup(val);
 	}
 
 	val = of_get_property(node, "polarity", NULL);
Signature · 1 line
1.5.6.5
Applied
#5 lore raw
Quoted 8 lines · Dirk Eibach

pca953x_get_alt_pdata() uses uint16_t* as result type for of_get_property(), but numeric of values are __be32.

Checking for negative values is bogus because of-property values are unsigned by definition.
Instead check for proper property size.

Applied, thanks.

g.