Skip to contentSkip to conversation

iio: magnetometer: ak8975: Silence 'may be used uninitialized' warning

PATCH In review [email protected] 3 participants 6 messages Jan 9, 2016 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: magnetometer: ak8975: Silence 'may be used uninitialized' warning

From: Tim Gardner <[email protected]>

drivers/iio/magnetometer/ak8975.c: In function 'ak8975_probe':
drivers/iio/magnetometer/ak8975.c:788:14: warning: 'chipset' may be used uninitialized in this function [-Wmaybe-uninitialized]
data->def = &ak_def_array[chipset];

gcc version 5.3.1 20151219 (Ubuntu 5.3.1-4ubuntu1)

Cc Jonathan Cameron <[email protected]>
Cc Hartmut Knaack <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc Srinivas Pandruvada <[email protected]>

---

This seems like a legitimate warning, though gcc should have complained about an earlier use of chipset on line 782.

 drivers/iio/magnetometer/ak8975.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/magnetometer/ak8975.c +1 -1
index b13936d..80ec0ce 100644
@@ -732,7 +732,7 @@ static int ak8975_probe(struct i2c_client *client,
 	int eoc_gpio;
 	int err;
 	const char *name = NULL;
-	enum asahi_compass_chipset chipset;
+	enum asahi_compass_chipset chipset = AK_MAX_TYPE;
 
 	/* Grab and set up the supplied GPIO. */
 	if (client->dev.platform_data)
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 6 lines · On 09/01/16 00:17, [email protected] wrote:

From: Tim Gardner <[email protected]>

drivers/iio/magnetometer/ak8975.c: In function 'ak8975_probe':
drivers/iio/magnetometer/ak8975.c:788:14: warning: 'chipset' may be used uninitialized in this function [-Wmaybe-uninitialized]
data->def = &ak_def_array[chipset];

Quoted 8 lines

gcc version 5.3.1 20151219 (Ubuntu 5.3.1-4ubuntu1)

Cc Jonathan Cameron <[email protected]>
Cc Hartmut Knaack <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc Srinivas Pandruvada <[email protected]>

Doesn't look to be an actual bug as we either end up with chipset being filled based on the traditional match table in which case it'll be assigned or based on the acpi match, which should succeed seeing as we've already had to have matched one or the other for the probe to match in the first place.

So probably worth the change to make it easier to tell that it should be fine and suppress the warning. However, whilst we are here, I note that *match_acpi_table has a path which returns NULL as the name and doesn't assign the chipset. We should be therefore checking if (!name) return -ENOSYS; Though maybe another error code would be more appropriate.

Not sure that error path can actually happen either, but if we are going to bother having the error path out of match_acpi_table then we ought to actually handle it!

Don't suppose you'd mind fixing that one as well whilst here?

Jonathan

Quoted 22 lines

---

This seems like a legitimate warning, though gcc should have complained about an earlier use of chipset on line 782.

 drivers/iio/magnetometer/ak8975.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/magnetometer/ak8975.c +1 -1
index b13936d..80ec0ce 100644
@@ -732,7 +732,7 @@ static int ak8975_probe(struct i2c_client *client,
 	int eoc_gpio;
 	int err;
 	const char *name = NULL;
-	enum asahi_compass_chipset chipset;
+	enum asahi_compass_chipset chipset = AK_MAX_TYPE;
 
 	/* Grab and set up the supplied GPIO. */
 	if (client->dev.platform_data)
#2 lore raw
Quoted 24 lines · Jonathan Cameron
Quoted 7 lines · On 09/01/16 00:17, [email protected] wrote:

From: Tim Gardner <[email protected]>

drivers/iio/magnetometer/ak8975.c: In function 'ak8975_probe':
drivers/iio/magnetometer/ak8975.c:788:14: warning: 'chipset' may be used uninitialized in this function [-Wmaybe-uninitialized]
data->def = &ak_def_array[chipset];

Quoted 8 lines

gcc version 5.3.1 20151219 (Ubuntu 5.3.1-4ubuntu1)

Cc Jonathan Cameron <[email protected]>
Cc Hartmut Knaack <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc Srinivas Pandruvada <[email protected]>

Doesn't look to be an actual bug as we either end up with chipset being filled
based on the traditional match table in which case it'll be assigned or based on the acpi match, which should succeed seeing as we've already
had to have matched one or the other for the probe to match in the first place.

Quoted 9 lines

So probably worth the change to make it easier to tell that it should be fine
and suppress the warning. However, whilst we are here, I note that *match_acpi_table has a path which returns NULL as the name and doesn't assign
the chipset. We should be therefore checking if (!name) return -ENOSYS;
Though maybe another error code would be more appropriate.

Since in this case we are enumerated by ACPI using our match table, so name can't be null. The "name" we provided in
static const struct acpi_device_id ak_acpi_match[] = {..} Same with the *chipset. Other than suppress warnings, I don't think it will cause any real issue.

Thanks,
Srinivas

Quoted 35 lines

Not sure that error path can actually happen either, but if we are going to
bother having the error path out of match_acpi_table then we ought to actually
handle it!

Don't suppose you'd mind fixing that one as well whilst here?

Jonathan

Quoted 25 lines

---

This seems like a legitimate warning, though gcc should have complained
about an earlier use of chipset on line 782.

 drivers/iio/magnetometer/ak8975.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/magnetometer/ak8975.c +1 -1
index b13936d..80ec0ce 100644
@@ -732,7 +732,7 @@ static int ak8975_probe(struct i2c_client
 *client,
 	int eoc_gpio;
 	int err;
 	const char *name = NULL;
-	enum asahi_compass_chipset chipset;
+	enum asahi_compass_chipset chipset = AK_MAX_TYPE;
 
 	/* Grab and set up the supplied GPIO. */

if (client->dev.platform_data)

maintainer
#3 lore raw
Quoted 35 lines · Srinivas Pandruvada
Quoted 24 lines · Jonathan Cameron
Quoted 7 lines · On 09/01/16 00:17, [email protected] wrote:

From: Tim Gardner <[email protected]>

drivers/iio/magnetometer/ak8975.c: In function 'ak8975_probe':
drivers/iio/magnetometer/ak8975.c:788:14: warning: 'chipset' may be used uninitialized in this function [-Wmaybe-uninitialized]
data->def = &ak_def_array[chipset];

Quoted 8 lines

gcc version 5.3.1 20151219 (Ubuntu 5.3.1-4ubuntu1)

Cc Jonathan Cameron <[email protected]>
Cc Hartmut Knaack <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc Srinivas Pandruvada <[email protected]>

Doesn't look to be an actual bug as we either end up with chipset being filled
based on the traditional match table in which case it'll be assigned or based on the acpi match, which should succeed seeing as we've already
had to have matched one or the other for the probe to match in the first place.

Quoted 9 lines

So probably worth the change to make it easier to tell that it should be fine
and suppress the warning. However, whilst we are here, I note that *match_acpi_table has a path which returns NULL as the name and doesn't assign
the chipset. We should be therefore checking if (!name) return -ENOSYS;
Though maybe another error code would be more appropriate.

Quoted 5 lines

Since in this case we are enumerated by ACPI using our match table, so name can't be null. The "name" we provided in
static const struct acpi_device_id ak_acpi_match[] = {..} Same with the *chipset. Other than suppress warnings, I don't think it will cause any real issue.

True enough, in which case why are we checking the name?
I'd be included to drop that check and add a comment.
I haven't chased every path, but I think that might deal with the above warning at it's root.

Quoted 44 lines

Thanks,
Srinivas

Quoted 31 lines

Not sure that error path can actually happen either, but if we are going to
bother having the error path out of match_acpi_table then we ought to actually
handle it!

Don't suppose you'd mind fixing that one as well whilst here?

Jonathan

Quoted 22 lines

---

This seems like a legitimate warning, though gcc should have complained
about an earlier use of chipset on line 782.

 drivers/iio/magnetometer/ak8975.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/magnetometer/ak8975.c +1 -1
index b13936d..80ec0ce 100644
@@ -732,7 +732,7 @@ static int ak8975_probe(struct i2c_client
 *client,
 	int eoc_gpio;
 	int err;
 	const char *name = NULL;
-	enum asahi_compass_chipset chipset;
+	enum asahi_compass_chipset chipset = AK_MAX_TYPE;
 
Quoted 4 lines
Quoted 3 lines
drivers/iio/magnetometer/ak8975.c +0 -0
 	/* Grab and set up the supplied GPIO. */

if (client->dev.platform_data)

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 1 line · Jonathan Cameron
Quoted 40 lines · Srinivas Pandruvada
Quoted 40 lines · Jonathan Cameron
Quoted 38 lines · On 09/01/16 00:17, [email protected] wrote:
Quoted 8 lines

From: Tim Gardner <[email protected]>

drivers/iio/magnetometer/ak8975.c: In function 'ak8975_probe':
drivers/iio/magnetometer/ak8975.c:788:14: warning: 'chipset' may be
used uninitialized in this function [-Wmaybe-uninitialized]
data->def = &ak_def_array[chipset];

Quoted 8 lines

gcc version 5.3.1 20151219 (Ubuntu 5.3.1-4ubuntu1)

Cc Jonathan Cameron <[email protected]>
Cc Hartmut Knaack <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc Srinivas Pandruvada <[email protected]>

Doesn't look to be an actual bug as we either end up with chipset being filled
based on the traditional match table in which case it'll be assigned
or based on the acpi match, which should succeed seeing as we've already
had to have matched one or the other for the probe to match in the
first place.

So probably worth the change to make it easier to tell that it should
be fine
and suppress the warning. However, whilst we are here, I note that
*match_acpi_table has a path which returns NULL as the name and doesn't assign
the chipset. We should be therefore checking if (!name) return -ENOSYS;
Though maybe another error code would be more appropriate.

Quoted 8 lines
Quoted 7 lines

Since in this case we are enumerated by ACPI using our match table, so
name can't be null. The "name" we provided in
static const struct acpi_device_id ak_acpi_match[] = {..} Same with the *chipset. Other than suppress warnings, I don't think it
will cause any real issue.

True enough, in which case why are we checking the name?

We can remove this check for !id
id = acpi_match_device(dev->driver->acpi_match_table, dev);
- if (!id)
- return NULL;
*chipset = (int)id->driver_data;

Thanks,
Srinivas

Quoted 51 lines

I'd be included to drop that check and add a comment.
I haven't chased every path, but I think that might deal with the above
warning at it's root.

Quoted 46 lines

Thanks,
Srinivas

Quoted 33 lines

Not sure that error path can actually happen either, but if we are
going to
bother having the error path out of match_acpi_table then we ought to
actually
handle it!

Don't suppose you'd mind fixing that one as well whilst here?

Jonathan

Quoted 22 lines

---

This seems like a legitimate warning, though gcc should have complained
about an earlier use of chipset on line 782.

 drivers/iio/magnetometer/ak8975.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/magnetometer/ak8975.c +1 -1
index b13936d..80ec0ce 100644
@@ -732,7 +732,7 @@ static int ak8975_probe(struct i2c_client
 *client,
 	int eoc_gpio;
 	int err;
 	const char *name = NULL;
-	enum asahi_compass_chipset chipset;
+	enum asahi_compass_chipset chipset = AK_MAX_TYPE;
 
Quoted 4 lines
Quoted 3 lines
drivers/iio/magnetometer/ak8975.c +0 -0
 	/* Grab and set up the supplied GPIO. */

if (client->dev.platform_data)

--
To unsubscribe from this list: send the line "unsubscribe linux -iio" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#5 lore raw
Quoted 55 lines · Srinivas Pandruvada
Quoted 1 line · Jonathan Cameron
Quoted 40 lines · Srinivas Pandruvada
Quoted 40 lines · Jonathan Cameron
Quoted 38 lines · On 09/01/16 00:17, [email protected] wrote:
Quoted 8 lines

From: Tim Gardner <[email protected]>

drivers/iio/magnetometer/ak8975.c: In function 'ak8975_probe':
drivers/iio/magnetometer/ak8975.c:788:14: warning: 'chipset' may be
used uninitialized in this function [-Wmaybe-uninitialized]
data->def = &ak_def_array[chipset];

Quoted 8 lines

gcc version 5.3.1 20151219 (Ubuntu 5.3.1-4ubuntu1)

Cc Jonathan Cameron <[email protected]>
Cc Hartmut Knaack <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc Srinivas Pandruvada <[email protected]>

Doesn't look to be an actual bug as we either end up with chipset being filled
based on the traditional match table in which case it'll be assigned
or based on the acpi match, which should succeed seeing as we've already
had to have matched one or the other for the probe to match in the
first place.

So probably worth the change to make it easier to tell that it should
be fine
and suppress the warning. However, whilst we are here, I note that
*match_acpi_table has a path which returns NULL as the name and doesn't assign
the chipset. We should be therefore checking if (!name) return -ENOSYS;
Though maybe another error code would be more appropriate.

Quoted 8 lines
Quoted 7 lines

Since in this case we are enumerated by ACPI using our match table, so
name can't be null. The "name" we provided in
static const struct acpi_device_id ak_acpi_match[] = {..} Same with the *chipset. Other than suppress warnings, I don't think it
will cause any real issue.

True enough, in which case why are we checking the name?

We can remove this check for !id
id = acpi_match_device(dev->driver->acpi_match_table, dev);
- if (!id)

Review

Quoted 2 lines
(quoted diff) +0 -1
-	return NULL;
  *chipset = (int)id->driver_data;

Yes, that's the one I meant rather than the name!

I'm not getting the warning Tim is seeing anyway so I'll leave it to him to confirm if this clears that up as well (so we don't need the other patch).

Tim, as you are working on this issue, do you want to try the above and if it works post a patch making that change + adding a note where the check is removed to say it cannot fail so there is no need to check?

Thanks,

Jonathan

Quoted 61 lines

Thanks,
Srinivas

Quoted 51 lines

I'd be included to drop that check and add a comment.
I haven't chased every path, but I think that might deal with the above
warning at it's root.

Quoted 46 lines

Thanks,
Srinivas

Quoted 33 lines

Not sure that error path can actually happen either, but if we are
going to
bother having the error path out of match_acpi_table then we ought to
actually
handle it!

Don't suppose you'd mind fixing that one as well whilst here?

Jonathan

Quoted 22 lines

---

This seems like a legitimate warning, though gcc should have complained
about an earlier use of chipset on line 782.

 drivers/iio/magnetometer/ak8975.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/magnetometer/ak8975.c +1 -1
index b13936d..80ec0ce 100644
@@ -732,7 +732,7 @@ static int ak8975_probe(struct i2c_client
 *client,
 	int eoc_gpio;
 	int err;
 	const char *name = NULL;
-	enum asahi_compass_chipset chipset;
+	enum asahi_compass_chipset chipset = AK_MAX_TYPE;
 
Quoted 4 lines
Quoted 3 lines
drivers/iio/magnetometer/ak8975.c +0 -0
 	/* Grab and set up the supplied GPIO. */

if (client->dev.platform_data)

--
To unsubscribe from this list: send the line "unsubscribe linux -iio" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html