* [RFC PATCH] iio: ak8975: Make sure chipset is always initialized @ 2014-12-18 17:16 Daniel Baluta 2014-12-19 22:16 ` Hartmut Knaack 0 siblings, 1 reply; 12+ messages in thread From: Daniel Baluta @ 2014-12-18 17:16 UTC (permalink / raw) To: jic23 Cc: knaack.h, lars, pmeerw, gwendal, srinivas.pandruvada, beomho.seo, daniel.baluta, linux-iio, linux-kernel, octavian.purdila When using ACPI, if acpi_match_device fails then chipset enum will be uninitialized and &ak_def_array[chipset] will point to some bad address. This fixes the following compilation warning: 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]; Reported-by: Octavian Purdila <octavian.purdila@intel.com> Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> --- This is a RFC because while I'm pretty sure that chipset should be initialized with AK_MAX_TYPE in ak8975_match_acpi_device, I am not sure if we can live with a NULL return value of ak8975_match_acpi_device. Current implementation ignores return value of ak8975_match_acpi_device. The same situation is for kxcjk-1013, bmc150-accel, bmg160 and possible other drivers. drivers/iio/magnetometer/ak8975.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index 0d10a4b..cdf9e77 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -716,6 +716,7 @@ static const char *ak8975_match_acpi_device(struct device *dev, { const struct acpi_device_id *id; + *chipset = AK_MAX_TYPE; id = acpi_match_device(dev->driver->acpi_match_table, dev); if (!id) return NULL; -- 1.9.1 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH] iio: ak8975: Make sure chipset is always initialized 2014-12-18 17:16 [RFC PATCH] iio: ak8975: Make sure chipset is always initialized Daniel Baluta @ 2014-12-19 22:16 ` Hartmut Knaack 2014-12-19 22:25 ` Daniel Baluta 0 siblings, 1 reply; 12+ messages in thread From: Hartmut Knaack @ 2014-12-19 22:16 UTC (permalink / raw) To: Daniel Baluta, jic23 Cc: lars, pmeerw, gwendal, srinivas.pandruvada, beomho.seo, linux-iio, linux-kernel, octavian.purdila Daniel Baluta schrieb am 18.12.2014 um 18:16: > When using ACPI, if acpi_match_device fails then chipset enum will be > uninitialized and &ak_def_array[chipset] will point to some bad address. > > This fixes the following compilation warning: > > 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]; > > Reported-by: Octavian Purdila <octavian.purdila@intel.com> > Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> > --- > This is a RFC because while I'm pretty sure that chipset should be initialized > with AK_MAX_TYPE in ak8975_match_acpi_device, I am not sure if we can live with > a NULL return value of ak8975_match_acpi_device. Current implementation ignores > return value of ak8975_match_acpi_device. This seems to be the actual problem: these _match_acpi_device functions return NULL on failure, and this should be checked for. > > The same situation is for kxcjk-1013, bmc150-accel, bmg160 and possible other > drivers. > > drivers/iio/magnetometer/ak8975.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c > index 0d10a4b..cdf9e77 100644 > --- a/drivers/iio/magnetometer/ak8975.c > +++ b/drivers/iio/magnetometer/ak8975.c > @@ -716,6 +716,7 @@ static const char *ak8975_match_acpi_device(struct device *dev, > { > const struct acpi_device_id *id; > > + *chipset =K_MAX_TYPE; > id =cpi_match_device(dev->driver->acpi_match_table, dev); > if (!id) > return NULL; > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH] iio: ak8975: Make sure chipset is always initialized 2014-12-19 22:16 ` Hartmut Knaack @ 2014-12-19 22:25 ` Daniel Baluta 2014-12-20 21:26 ` Srinivas Pandruvada 0 siblings, 1 reply; 12+ messages in thread From: Daniel Baluta @ 2014-12-19 22:25 UTC (permalink / raw) To: Hartmut Knaack Cc: Daniel Baluta, Jonathan Cameron, Lars-Peter Clausen, Peter Meerwald, gwendal, Srinivas Pandruvada, beomho.seo, linux-iio, Linux Kernel Mailing List, octavian.purdila On Sat, Dec 20, 2014 at 12:16 AM, Hartmut Knaack <knaack.h@gmx.de> wrote: > Daniel Baluta schrieb am 18.12.2014 um 18:16: >> When using ACPI, if acpi_match_device fails then chipset enum will be >> uninitialized and &ak_def_array[chipset] will point to some bad address. >> >> This fixes the following compilation warning: >> >> 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]; >> >> Reported-by: Octavian Purdila <octavian.purdila@intel.com> >> Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> >> --- >> This is a RFC because while I'm pretty sure that chipset should be initialized >> with AK_MAX_TYPE in ak8975_match_acpi_device, I am not sure if we can live with >> a NULL return value of ak8975_match_acpi_device. Current implementation ignores >> return value of ak8975_match_acpi_device. > This seems to be the actual problem: these _match_acpi_device functions return > NULL on failure, and this should be checked for. Ok, so this would acceptable? diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index 0d10a4b..68d99e9 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -776,8 +776,9 @@ static int ak8975_probe(struct i2c_client *client, name = id->name; } else if (ACPI_HANDLE(&client->dev)) name = ak8975_match_acpi_device(&client->dev, &chipset); - else - return -ENOSYS; + + if (!name) + return -ENODEV; I still have some doubts about return code in case of error. For ak8975 we use -ENOSYS, but for kxcjk-1013 we use -ENODEV. I will send a patch after we clear this out. thanks, Daniel. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH] iio: ak8975: Make sure chipset is always initialized 2014-12-19 22:25 ` Daniel Baluta @ 2014-12-20 21:26 ` Srinivas Pandruvada 2014-12-20 21:29 ` Pandruvada, Srinivas 0 siblings, 1 reply; 12+ messages in thread From: Srinivas Pandruvada @ 2014-12-20 21:26 UTC (permalink / raw) To: Daniel Baluta Cc: Hartmut Knaack, Jonathan Cameron, Lars-Peter Clausen, Peter Meerwald, gwendal, beomho.seo, linux-iio, Linux Kernel Mailing List, octavian.purdila On Sat, 2014-12-20 at 00:25 +0200, Daniel Baluta wrote: > On Sat, Dec 20, 2014 at 12:16 AM, Hartmut Knaack <knaack.h@gmx.de> wrote: > > Daniel Baluta schrieb am 18.12.2014 um 18:16: > >> When using ACPI, if acpi_match_device fails then chipset enum will be > >> uninitialized and &ak_def_array[chipset] will point to some bad address. > >> I am missing something. You are enumerated over i2c device, which was created from ACPI PNP resource. There is a valid handle or and the device has an ACPI companion at the least. If this failing, I have to check the code for acpi i2c. Can you check why this check failed? We may have bug in i2c handling. Thanks, Srinivas > >> This fixes the following compilation warning: > >> > >> 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]; > >> > >> Reported-by: Octavian Purdila <octavian.purdila@intel.com> > >> Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> > >> --- > >> This is a RFC because while I'm pretty sure that chipset should be initialized > >> with AK_MAX_TYPE in ak8975_match_acpi_device, I am not sure if we can live with > >> a NULL return value of ak8975_match_acpi_device. Current implementation ignores > >> return value of ak8975_match_acpi_device. > > This seems to be the actual problem: these _match_acpi_device functions return > > NULL on failure, and this should be checked for. > > Ok, so this would acceptable? > > diff --git a/drivers/iio/magnetometer/ak8975.c > b/drivers/iio/magnetometer/ak8975.c > index 0d10a4b..68d99e9 100644 > --- a/drivers/iio/magnetometer/ak8975.c > +++ b/drivers/iio/magnetometer/ak8975.c > @@ -776,8 +776,9 @@ static int ak8975_probe(struct i2c_client *client, > name = id->name; > } else if (ACPI_HANDLE(&client->dev)) > name = ak8975_match_acpi_device(&client->dev, &chipset); > - else > - return -ENOSYS; > + > + if (!name) > + return -ENODEV; > > > I still have some doubts about return code in case of error. > > For ak8975 we use -ENOSYS, but for kxcjk-1013 we use -ENODEV. > > I will send a patch after we clear this out. > > thanks, > Daniel. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH] iio: ak8975: Make sure chipset is always initialized 2014-12-20 21:26 ` Srinivas Pandruvada @ 2014-12-20 21:29 ` Pandruvada, Srinivas 2014-12-20 21:40 ` Daniel Baluta 2015-01-19 14:40 ` Daniel Baluta 0 siblings, 2 replies; 12+ messages in thread From: Pandruvada, Srinivas @ 2014-12-20 21:29 UTC (permalink / raw) To: Baluta, Daniel Cc: lars, linux-kernel, knaack.h, jic23, Purdila, Octavian, linux-iio, Westerberg, Mika, pmeerw, beomho.seo, gwendal [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain; charset="utf-8", Size: 2689 bytes --] +Mika On Sat, 2014-12-20 at 13:26 -0800, Srinivas Pandruvada wrote: > On Sat, 2014-12-20 at 00:25 +0200, Daniel Baluta wrote: > > On Sat, Dec 20, 2014 at 12:16 AM, Hartmut Knaack <knaack.h@gmx.de> wrote: > > > Daniel Baluta schrieb am 18.12.2014 um 18:16: > > >> When using ACPI, if acpi_match_device fails then chipset enum will be > > >> uninitialized and &ak_def_array[chipset] will point to some bad address. > > >> > I am missing something. You are enumerated over i2c device, which was > created from ACPI PNP resource. There is a valid handle or and the > device has an ACPI companion at the least. If this failing, I have to > check the code for acpi i2c. > Can you check why this check failed? We may have bug in i2c handling. > > Thanks, > Srinivas > > > >> This fixes the following compilation warning: > > >> > > >> 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]; > > >> > > >> Reported-by: Octavian Purdila <octavian.purdila@intel.com> > > >> Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> > > >> --- > > >> This is a RFC because while I'm pretty sure that chipset should be initialized > > >> with AK_MAX_TYPE in ak8975_match_acpi_device, I am not sure if we can live with > > >> a NULL return value of ak8975_match_acpi_device. Current implementation ignores > > >> return value of ak8975_match_acpi_device. > > > This seems to be the actual problem: these _match_acpi_device functions return > > > NULL on failure, and this should be checked for. > > > > Ok, so this would acceptable? > > > > diff --git a/drivers/iio/magnetometer/ak8975.c > > b/drivers/iio/magnetometer/ak8975.c > > index 0d10a4b..68d99e9 100644 > > --- a/drivers/iio/magnetometer/ak8975.c > > +++ b/drivers/iio/magnetometer/ak8975.c > > @@ -776,8 +776,9 @@ static int ak8975_probe(struct i2c_client *client, > > name = id->name; > > } else if (ACPI_HANDLE(&client->dev)) > > name = ak8975_match_acpi_device(&client->dev, &chipset); > > - else > > - return -ENOSYS; > > + > > + if (!name) > > + return -ENODEV; > > > > > > I still have some doubts about return code in case of error. > > > > For ak8975 we use -ENOSYS, but for kxcjk-1013 we use -ENODEV. > > > > I will send a patch after we clear this out. > > > > thanks, > > Daniel. > ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥ ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH] iio: ak8975: Make sure chipset is always initialized 2014-12-20 21:29 ` Pandruvada, Srinivas @ 2014-12-20 21:40 ` Daniel Baluta 2015-01-19 14:40 ` Daniel Baluta 1 sibling, 0 replies; 12+ messages in thread From: Daniel Baluta @ 2014-12-20 21:40 UTC (permalink / raw) To: Pandruvada, Srinivas Cc: Baluta, Daniel, lars, linux-kernel, knaack.h, jic23, Purdila, Octavian, linux-iio, Westerberg, Mika, pmeerw, beomho.seo, gwendal I will have closer look on why acpi_match_device could fail. This patch was only based on code reading when trying to fix the compiler warning mentioned in the commit message. [Sorry for top posting] On Sat, Dec 20, 2014 at 11:29 PM, Pandruvada, Srinivas <srinivas.pandruvada@intel.com> wrote: > +Mika > > On Sat, 2014-12-20 at 13:26 -0800, Srinivas Pandruvada wrote: >> On Sat, 2014-12-20 at 00:25 +0200, Daniel Baluta wrote: >> > On Sat, Dec 20, 2014 at 12:16 AM, Hartmut Knaack <knaack.h@gmx.de> wrote: >> > > Daniel Baluta schrieb am 18.12.2014 um 18:16: >> > >> When using ACPI, if acpi_match_device fails then chipset enum will be >> > >> uninitialized and &ak_def_array[chipset] will point to some bad address. >> > >> >> I am missing something. You are enumerated over i2c device, which was >> created from ACPI PNP resource. There is a valid handle or and the >> device has an ACPI companion at the least. If this failing, I have to >> check the code for acpi i2c. >> Can you check why this check failed? We may have bug in i2c handling. >> >> Thanks, >> Srinivas >> >> > >> This fixes the following compilation warning: >> > >> >> > >> 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]; >> > >> >> > >> Reported-by: Octavian Purdila <octavian.purdila@intel.com> >> > >> Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> >> > >> --- >> > >> This is a RFC because while I'm pretty sure that chipset should be initialized >> > >> with AK_MAX_TYPE in ak8975_match_acpi_device, I am not sure if we can live with >> > >> a NULL return value of ak8975_match_acpi_device. Current implementation ignores >> > >> return value of ak8975_match_acpi_device. >> > > This seems to be the actual problem: these _match_acpi_device functions return >> > > NULL on failure, and this should be checked for. >> > >> > Ok, so this would acceptable? >> > >> > diff --git a/drivers/iio/magnetometer/ak8975.c >> > b/drivers/iio/magnetometer/ak8975.c >> > index 0d10a4b..68d99e9 100644 >> > --- a/drivers/iio/magnetometer/ak8975.c >> > +++ b/drivers/iio/magnetometer/ak8975.c >> > @@ -776,8 +776,9 @@ static int ak8975_probe(struct i2c_client *client, >> > name = id->name; >> > } else if (ACPI_HANDLE(&client->dev)) >> > name = ak8975_match_acpi_device(&client->dev, &chipset); >> > - else >> > - return -ENOSYS; >> > + >> > + if (!name) >> > + return -ENODEV; >> > >> > >> > I still have some doubts about return code in case of error. >> > >> > For ak8975 we use -ENOSYS, but for kxcjk-1013 we use -ENODEV. >> > >> > I will send a patch after we clear this out. >> > >> > thanks, >> > Daniel. >> > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH] iio: ak8975: Make sure chipset is always initialized 2014-12-20 21:29 ` Pandruvada, Srinivas 2014-12-20 21:40 ` Daniel Baluta @ 2015-01-19 14:40 ` Daniel Baluta 2015-01-19 16:44 ` Pandruvada, Srinivas 1 sibling, 1 reply; 12+ messages in thread From: Daniel Baluta @ 2015-01-19 14:40 UTC (permalink / raw) To: Pandruvada, Srinivas Cc: Baluta, Daniel, lars, linux-kernel, knaack.h, jic23, Purdila, Octavian, linux-iio, Westerberg, Mika, pmeerw, beomho.seo, gwendal Hello, On Sat, Dec 20, 2014 at 11:29 PM, Pandruvada, Srinivas <srinivas.pandruvada@intel.com> wrote: > +Mika > > On Sat, 2014-12-20 at 13:26 -0800, Srinivas Pandruvada wrote: >> On Sat, 2014-12-20 at 00:25 +0200, Daniel Baluta wrote: >> > On Sat, Dec 20, 2014 at 12:16 AM, Hartmut Knaack <knaack.h@gmx.de> wrote: >> > > Daniel Baluta schrieb am 18.12.2014 um 18:16: >> > >> When using ACPI, if acpi_match_device fails then chipset enum will be >> > >> uninitialized and &ak_def_array[chipset] will point to some bad address. >> > >> >> I am missing something. You are enumerated over i2c device, which was >> created from ACPI PNP resource. There is a valid handle or and the >> device has an ACPI companion at the least. If this failing, I have to >> check the code for acpi i2c. >> Can you check why this check failed? We may have bug in i2c handling. You are right about this. Under normal circumstances, if probe is called then acpi_match_device will not fail. I even tried to remove the device after probe but before acpi_match_device, anyhow acpi_match_device was still successful :) This is more a matter of code correctness. In ak8975_match_acpi_device we have: » const struct acpi_device_id *id; » id = acpi_match_device(dev->driver->acpi_match_table, dev); » if (!id) » » return NULL; » *chipset = (int)id->driver_data; Compiler complains on the fact that chipset might be uninitialized if this returns NULL, and we shouldn't ignore this warning even this case will never happen. We could use some code injection techniques to force acpi_match_device to return NULL tough. >> > >> This fixes the following compilation warning: >> > >> >> > >> 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]; >> > >> >> > >> Reported-by: Octavian Purdila <octavian.purdila@intel.com> >> > >> Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> >> > >> --- >> > >> This is a RFC because while I'm pretty sure that chipset should be initialized >> > >> with AK_MAX_TYPE in ak8975_match_acpi_device, I am not sure if we can live with >> > >> a NULL return value of ak8975_match_acpi_device. Current implementation ignores >> > >> return value of ak8975_match_acpi_device. >> > > This seems to be the actual problem: these _match_acpi_device functions return >> > > NULL on failure, and this should be checked for. >> > >> > Ok, so this would acceptable? >> > >> > diff --git a/drivers/iio/magnetometer/ak8975.c >> > b/drivers/iio/magnetometer/ak8975.c >> > index 0d10a4b..68d99e9 100644 >> > --- a/drivers/iio/magnetometer/ak8975.c >> > +++ b/drivers/iio/magnetometer/ak8975.c >> > @@ -776,8 +776,9 @@ static int ak8975_probe(struct i2c_client *client, >> > name = id->name; >> > } else if (ACPI_HANDLE(&client->dev)) >> > name = ak8975_match_acpi_device(&client->dev, &chipset); >> > - else >> > - return -ENOSYS; >> > + >> > + if (!name) >> > + return -ENODEV; >> > >> > >> > I still have some doubts about return code in case of error. >> > >> > For ak8975 we use -ENOSYS, but for kxcjk-1013 we use -ENODEV. >> > >> > I will send a patch after we clear this out. >> > >> > thanks, >> > Daniel. >> > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH] iio: ak8975: Make sure chipset is always initialized 2015-01-19 14:40 ` Daniel Baluta @ 2015-01-19 16:44 ` Pandruvada, Srinivas 2015-01-19 16:49 ` Daniel Baluta 0 siblings, 1 reply; 12+ messages in thread From: Pandruvada, Srinivas @ 2015-01-19 16:44 UTC (permalink / raw) To: Baluta, Daniel Cc: lars, linux-kernel, knaack.h, jic23, Purdila, Octavian, linux-iio, Westerberg, Mika, pmeerw, beomho.seo, gwendal [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain; charset="utf-8", Size: 3949 bytes --] On Mon, 2015-01-19 at 16:40 +0200, Daniel Baluta wrote: > Hello, > > On Sat, Dec 20, 2014 at 11:29 PM, Pandruvada, Srinivas > <srinivas.pandruvada@intel.com> wrote: > > +Mika > > > > On Sat, 2014-12-20 at 13:26 -0800, Srinivas Pandruvada wrote: > >> On Sat, 2014-12-20 at 00:25 +0200, Daniel Baluta wrote: > >> > On Sat, Dec 20, 2014 at 12:16 AM, Hartmut Knaack <knaack.h@gmx.de> wrote: > >> > > Daniel Baluta schrieb am 18.12.2014 um 18:16: > >> > >> When using ACPI, if acpi_match_device fails then chipset enum will be > >> > >> uninitialized and &ak_def_array[chipset] will point to some bad address. > >> > >> > >> I am missing something. You are enumerated over i2c device, which was > >> created from ACPI PNP resource. There is a valid handle or and the > >> device has an ACPI companion at the least. If this failing, I have to > >> check the code for acpi i2c. > >> Can you check why this check failed? We may have bug in i2c handling. > > You are right about this. Under normal circumstances, if probe is called > then acpi_match_device will not fail. I even tried to remove the > device after probe > but before acpi_match_device, anyhow acpi_match_device was still successful :) > > This is more a matter of code correctness. > > In ak8975_match_acpi_device we have: > > » const struct acpi_device_id *id; > > » id = acpi_match_device(dev->driver->acpi_match_table, dev); > » if (!id) > » » return NULL; > » *chipset = (int)id->driver_data; > > Compiler complains on the fact that chipset might be uninitialized > if this returns NULL, and we shouldn't ignore this warning even this case > will never happen. > Will this fix? data->chipset = AK8975; before ak8975_match_acpi_device(&client->dev, &data->chipset); Thanks, Srinivas > We could use some code injection techniques to force acpi_match_device > to return NULL tough. > > >> > >> This fixes the following compilation warning: > >> > >> > >> > >> 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]; > >> > >> > >> > >> Reported-by: Octavian Purdila <octavian.purdila@intel.com> > >> > >> Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> > >> > >> --- > >> > >> This is a RFC because while I'm pretty sure that chipset should be initialized > >> > >> with AK_MAX_TYPE in ak8975_match_acpi_device, I am not sure if we can live with > >> > >> a NULL return value of ak8975_match_acpi_device. Current implementation ignores > >> > >> return value of ak8975_match_acpi_device. > >> > > This seems to be the actual problem: these _match_acpi_device functions return > >> > > NULL on failure, and this should be checked for. > >> > > >> > Ok, so this would acceptable? > >> > > >> > diff --git a/drivers/iio/magnetometer/ak8975.c > >> > b/drivers/iio/magnetometer/ak8975.c > >> > index 0d10a4b..68d99e9 100644 > >> > --- a/drivers/iio/magnetometer/ak8975.c > >> > +++ b/drivers/iio/magnetometer/ak8975.c > >> > @@ -776,8 +776,9 @@ static int ak8975_probe(struct i2c_client *client, > >> > name = id->name; > >> > } else if (ACPI_HANDLE(&client->dev)) > >> > name = ak8975_match_acpi_device(&client->dev, &chipset); > >> > - else > >> > - return -ENOSYS; > >> > + > >> > + if (!name) > >> > + return -ENODEV; > >> > > >> > > >> > I still have some doubts about return code in case of error. > >> > > >> > For ak8975 we use -ENOSYS, but for kxcjk-1013 we use -ENODEV. > >> > > >> > I will send a patch after we clear this out. > >> > > >> > thanks, > >> > Daniel. > >> > > ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥ ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH] iio: ak8975: Make sure chipset is always initialized 2015-01-19 16:44 ` Pandruvada, Srinivas @ 2015-01-19 16:49 ` Daniel Baluta 2015-01-19 16:56 ` Pandruvada, Srinivas 0 siblings, 1 reply; 12+ messages in thread From: Daniel Baluta @ 2015-01-19 16:49 UTC (permalink / raw) To: Pandruvada, Srinivas Cc: Baluta, Daniel, lars, linux-kernel, knaack.h, jic23, Purdila, Octavian, linux-iio, Westerberg, Mika, pmeerw, beomho.seo, gwendal On Mon, Jan 19, 2015 at 6:44 PM, Pandruvada, Srinivas <srinivas.pandruvada@intel.com> wrote: > On Mon, 2015-01-19 at 16:40 +0200, Daniel Baluta wrote: >> Hello, >> >> On Sat, Dec 20, 2014 at 11:29 PM, Pandruvada, Srinivas >> <srinivas.pandruvada@intel.com> wrote: >> > +Mika >> > >> > On Sat, 2014-12-20 at 13:26 -0800, Srinivas Pandruvada wrote: >> >> On Sat, 2014-12-20 at 00:25 +0200, Daniel Baluta wrote: >> >> > On Sat, Dec 20, 2014 at 12:16 AM, Hartmut Knaack <knaack.h@gmx.de> wrote: >> >> > > Daniel Baluta schrieb am 18.12.2014 um 18:16: >> >> > >> When using ACPI, if acpi_match_device fails then chipset enum will be >> >> > >> uninitialized and &ak_def_array[chipset] will point to some bad address. >> >> > >> >> >> I am missing something. You are enumerated over i2c device, which was >> >> created from ACPI PNP resource. There is a valid handle or and the >> >> device has an ACPI companion at the least. If this failing, I have to >> >> check the code for acpi i2c. >> >> Can you check why this check failed? We may have bug in i2c handling. >> >> You are right about this. Under normal circumstances, if probe is called >> then acpi_match_device will not fail. I even tried to remove the >> device after probe >> but before acpi_match_device, anyhow acpi_match_device was still successful :) >> >> This is more a matter of code correctness. >> >> In ak8975_match_acpi_device we have: >> >> » const struct acpi_device_id *id; >> >> » id = acpi_match_device(dev->driver->acpi_match_table, dev); >> » if (!id) >> » » return NULL; >> » *chipset = (int)id->driver_data; >> >> Compiler complains on the fact that chipset might be uninitialized >> if this returns NULL, and we shouldn't ignore this warning even this case >> will never happen. >> > Will this fix? > data->chipset = AK8975; > before > ak8975_match_acpi_device(&client->dev, &data->chipset); > Yes, this is done in the original patch: + *chipset = AK_MAX_TYPE; .. and fixes the warning. Daniel. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH] iio: ak8975: Make sure chipset is always initialized 2015-01-19 16:49 ` Daniel Baluta @ 2015-01-19 16:56 ` Pandruvada, Srinivas 2015-01-23 23:38 ` Hartmut Knaack 0 siblings, 1 reply; 12+ messages in thread From: Pandruvada, Srinivas @ 2015-01-19 16:56 UTC (permalink / raw) To: Baluta, Daniel Cc: lars, linux-kernel, knaack.h, jic23, Purdila, Octavian, linux-iio, Westerberg, Mika, pmeerw, beomho.seo, gwendal [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain; charset="utf-8", Size: 2471 bytes --] On Mon, 2015-01-19 at 18:49 +0200, Daniel Baluta wrote: > On Mon, Jan 19, 2015 at 6:44 PM, Pandruvada, Srinivas > <srinivas.pandruvada@intel.com> wrote: > > On Mon, 2015-01-19 at 16:40 +0200, Daniel Baluta wrote: > >> Hello, > >> > >> On Sat, Dec 20, 2014 at 11:29 PM, Pandruvada, Srinivas > >> <srinivas.pandruvada@intel.com> wrote: > >> > +Mika > >> > > >> > On Sat, 2014-12-20 at 13:26 -0800, Srinivas Pandruvada wrote: > >> >> On Sat, 2014-12-20 at 00:25 +0200, Daniel Baluta wrote: > >> >> > On Sat, Dec 20, 2014 at 12:16 AM, Hartmut Knaack <knaack.h@gmx.de> wrote: > >> >> > > Daniel Baluta schrieb am 18.12.2014 um 18:16: > >> >> > >> When using ACPI, if acpi_match_device fails then chipset enum will be > >> >> > >> uninitialized and &ak_def_array[chipset] will point to some bad address. > >> >> > >> > >> >> I am missing something. You are enumerated over i2c device, which was > >> >> created from ACPI PNP resource. There is a valid handle or and the > >> >> device has an ACPI companion at the least. If this failing, I have to > >> >> check the code for acpi i2c. > >> >> Can you check why this check failed? We may have bug in i2c handling. > >> > >> You are right about this. Under normal circumstances, if probe is called > >> then acpi_match_device will not fail. I even tried to remove the > >> device after probe > >> but before acpi_match_device, anyhow acpi_match_device was still successful :) > >> > >> This is more a matter of code correctness. > >> > >> In ak8975_match_acpi_device we have: > >> > >> » const struct acpi_device_id *id; > >> > >> » id = acpi_match_device(dev->driver->acpi_match_table, dev); > >> » if (!id) > >> » » return NULL; > >> » *chipset = (int)id->driver_data; > >> > >> Compiler complains on the fact that chipset might be uninitialized > >> if this returns NULL, and we shouldn't ignore this warning even this case > >> will never happen. > >> > > Will this fix? > > data->chipset = AK8975; > > before > > ak8975_match_acpi_device(&client->dev, &data->chipset); > > > > Yes, this is done in the original patch: > > + *chipset = AK_MAX_TYPE; Since data memory is not zero alloced, other member of data are anyway initialized, so adding this also may be better. > > .. and fixes the warning. > > Daniel. ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥ ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH] iio: ak8975: Make sure chipset is always initialized 2015-01-19 16:56 ` Pandruvada, Srinivas @ 2015-01-23 23:38 ` Hartmut Knaack 2015-01-24 0:17 ` Pandruvada, Srinivas 0 siblings, 1 reply; 12+ messages in thread From: Hartmut Knaack @ 2015-01-23 23:38 UTC (permalink / raw) To: Pandruvada, Srinivas, Baluta, Daniel Cc: lars, linux-kernel, jic23, Purdila, Octavian, linux-iio, Westerberg, Mika, pmeerw, beomho.seo, gwendal Pandruvada, Srinivas schrieb am 19.01.2015 um 17:56: > On Mon, 2015-01-19 at 18:49 +0200, Daniel Baluta wrote: >> On Mon, Jan 19, 2015 at 6:44 PM, Pandruvada, Srinivas >> <srinivas.pandruvada@intel.com> wrote: >>> On Mon, 2015-01-19 at 16:40 +0200, Daniel Baluta wrote: >>>> Hello, >>>> >>>> On Sat, Dec 20, 2014 at 11:29 PM, Pandruvada, Srinivas >>>> <srinivas.pandruvada@intel.com> wrote: >>>>> +Mika >>>>> >>>>> On Sat, 2014-12-20 at 13:26 -0800, Srinivas Pandruvada wrote: >>>>>> On Sat, 2014-12-20 at 00:25 +0200, Daniel Baluta wrote: >>>>>>> On Sat, Dec 20, 2014 at 12:16 AM, Hartmut Knaack <knaack.h@gmx.de> wrote: >>>>>>>> Daniel Baluta schrieb am 18.12.2014 um 18:16: >>>>>>>>> When using ACPI, if acpi_match_device fails then chipset enum will be >>>>>>>>> uninitialized and &ak_def_array[chipset] will point to some bad address. >>>>>>>>> >>>>>> I am missing something. You are enumerated over i2c device, which was >>>>>> created from ACPI PNP resource. There is a valid handle or and the >>>>>> device has an ACPI companion at the least. If this failing, I have to >>>>>> check the code for acpi i2c. >>>>>> Can you check why this check failed? We may have bug in i2c handling. >>>> >>>> You are right about this. Under normal circumstances, if probe is called >>>> then acpi_match_device will not fail. I even tried to remove the >>>> device after probe >>>> but before acpi_match_device, anyhow acpi_match_device was still successful :) >>>> >>>> This is more a matter of code correctness. >>>> >>>> In ak8975_match_acpi_device we have: >>>> >>>> » const struct acpi_device_id *id; >>>> >>>> » id = acpi_match_device(dev->driver->acpi_match_table, dev); >>>> » if (!id) >>>> » » return NULL; >>>> » *chipset = (int)id->driver_data; >>>> >>>> Compiler complains on the fact that chipset might be uninitialized >>>> if this returns NULL, and we shouldn't ignore this warning even this case >>>> will never happen. >>>> >>> Will this fix? >>> data->chipset = AK8975; >>> before >>> ak8975_match_acpi_device(&client->dev, &data->chipset); >>> This would fix the compiler warning, but doesn't seem the right solution for this issue. Quoting the description of acpi_match_device: "Return a pointer to the first matching ID on success or %NULL on failure." So, even if it is very unlikely to for it to fail - if it does fail, the error should be handled as quick as possible. I would favor Daniels solution to check for a valid assignment of name. >> >> Yes, this is done in the original patch: >> >> + *chipset = AK_MAX_TYPE; > Since data memory is not zero alloced, other member of data are anyway > initialized, so adding this also may be better. If there did not occur an error condition, it will be assigned a value before being checked for valid ranges. And if there is an error, probe should be aborted, anyway. So initializing *chipset doesn't seem to add any benefit IMHO. >> >> .. and fixes the warning. >> >> Daniel. > > N�����r��y���b�X��ǧv�^�){.n�+����{��*"��^n�r���z�\x1a��h����&��\x1e�G���h�\x03(�階�ݢj"��\x1a�^[m�����z�ޖ���f���h���~�mml== > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC PATCH] iio: ak8975: Make sure chipset is always initialized 2015-01-23 23:38 ` Hartmut Knaack @ 2015-01-24 0:17 ` Pandruvada, Srinivas 0 siblings, 0 replies; 12+ messages in thread From: Pandruvada, Srinivas @ 2015-01-24 0:17 UTC (permalink / raw) To: knaack.h Cc: Baluta, Daniel, lars, linux-kernel, jic23, Purdila, Octavian, linux-iio, Westerberg, Mika, pmeerw, beomho.seo, gwendal [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain; charset="utf-8", Size: 3734 bytes --] On Sat, 2015-01-24 at 00:38 +0100, Hartmut Knaack wrote: > Pandruvada, Srinivas schrieb am 19.01.2015 um 17:56: > > On Mon, 2015-01-19 at 18:49 +0200, Daniel Baluta wrote: > >> On Mon, Jan 19, 2015 at 6:44 PM, Pandruvada, Srinivas > >> <srinivas.pandruvada@intel.com> wrote: > >>> On Mon, 2015-01-19 at 16:40 +0200, Daniel Baluta wrote: > >>>> Hello, > >>>> > >>>> On Sat, Dec 20, 2014 at 11:29 PM, Pandruvada, Srinivas > >>>> <srinivas.pandruvada@intel.com> wrote: > >>>>> +Mika > >>>>> > >>>>> On Sat, 2014-12-20 at 13:26 -0800, Srinivas Pandruvada wrote: > >>>>>> On Sat, 2014-12-20 at 00:25 +0200, Daniel Baluta wrote: > >>>>>>> On Sat, Dec 20, 2014 at 12:16 AM, Hartmut Knaack <knaack.h@gmx.de> wrote: > >>>>>>>> Daniel Baluta schrieb am 18.12.2014 um 18:16: > >>>>>>>>> When using ACPI, if acpi_match_device fails then chipset enum will be > >>>>>>>>> uninitialized and &ak_def_array[chipset] will point to some bad address. > >>>>>>>>> > >>>>>> I am missing something. You are enumerated over i2c device, which was > >>>>>> created from ACPI PNP resource. There is a valid handle or and the > >>>>>> device has an ACPI companion at the least. If this failing, I have to > >>>>>> check the code for acpi i2c. > >>>>>> Can you check why this check failed? We may have bug in i2c handling. > >>>> > >>>> You are right about this. Under normal circumstances, if probe is called > >>>> then acpi_match_device will not fail. I even tried to remove the > >>>> device after probe > >>>> but before acpi_match_device, anyhow acpi_match_device was still successful :) > >>>> > >>>> This is more a matter of code correctness. > >>>> > >>>> In ak8975_match_acpi_device we have: > >>>> > >>>> » const struct acpi_device_id *id; > >>>> > >>>> » id = acpi_match_device(dev->driver->acpi_match_table, dev); > >>>> » if (!id) > >>>> » » return NULL; > >>>> » *chipset = (int)id->driver_data; > >>>> > >>>> Compiler complains on the fact that chipset might be uninitialized > >>>> if this returns NULL, and we shouldn't ignore this warning even this case > >>>> will never happen. > >>>> > >>> Will this fix? > >>> data->chipset = AK8975; > >>> before > >>> ak8975_match_acpi_device(&client->dev, &data->chipset); > >>> > > This would fix the compiler warning, but doesn't seem the right solution for > this issue. Quoting the description of acpi_match_device: > "Return a pointer to the first matching ID on success or %NULL on failure." > So, even if it is very unlikely to for it to fail - if it does fail, the > error should be handled as quick as possible. I would favor Daniels solution > to check for a valid assignment of name. > This should never fail as the device is enumerated by this. So it doesn't matter as long as you silent compiler warning. > >> > >> Yes, this is done in the original patch: > >> > >> + *chipset = AK_MAX_TYPE; > > Since data memory is not zero alloced, other member of data are anyway > > initialized, so adding this also may be better. > > If there did not occur an error condition, it will be assigned a value > before being checked for valid ranges. And if there is an error, probe > should be aborted, anyway. So initializing *chipset doesn't seem to add > any benefit IMHO. > > >> > >> .. and fixes the warning. > >> > >> Daniel. > > > > N�����r��y���b�X��ǧv�^�)Þº{.n�+����{��*"��^n�r���z�\x1a��h����&��\x1e�G���h�\x03(�é�ݢj"��\x1a�^[m�����z�Þ���f���h���~�mml== > > > ÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥ ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2015-01-24 0:17 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-12-18 17:16 [RFC PATCH] iio: ak8975: Make sure chipset is always initialized Daniel Baluta 2014-12-19 22:16 ` Hartmut Knaack 2014-12-19 22:25 ` Daniel Baluta 2014-12-20 21:26 ` Srinivas Pandruvada 2014-12-20 21:29 ` Pandruvada, Srinivas 2014-12-20 21:40 ` Daniel Baluta 2015-01-19 14:40 ` Daniel Baluta 2015-01-19 16:44 ` Pandruvada, Srinivas 2015-01-19 16:49 ` Daniel Baluta 2015-01-19 16:56 ` Pandruvada, Srinivas 2015-01-23 23:38 ` Hartmut Knaack 2015-01-24 0:17 ` Pandruvada, Srinivas
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®