Skip to contentSkip to conversation

iio: initialise ddata for iio_get_acpi_device_name_and_data()

PATCH In review Andy Shevchenko 2 participants 7 messages Nov 1, 2024 IIO

lore
Share & tools
lore
#0 lore raw

v3 cover iio: initialise ddata for iio_get_acpi_device_name_and_data()

Dan reported that ddata might be used uninitialised in some cases. Let's initialise it to NULL (patches 1 - 3). With that, update one driver to drop an unneeded anymore check (included in patch 3).

While at it, one more cleanup to kxcjk-1013 (patch 4) is added.

Jonathan, dunno if you want to rebase at this stage (probably not), but if you do, feel free to fold the patches 1-3 to the initial code.

In v3:
- made Subject more specific for patches 1-3 (Markus)

In v2:
- rewritten patches 1-3 to do the job on the caller side (Jonathan)

Andy Shevchenko (4):
iio: light: isl29018: Assign NULL to ddata in isl29018_probe()
iio: light: ltr501: Assign NULL to ddata in ltr501_probe()
iio: accel: kxcjk-1013: Assign NULL to ddata in kxcjk1013_probe()
iio: accel: kxcjk-1013: Deduplicate ODR startup time array

 drivers/iio/accel/kxcjk-1013.c | 30 ++++++------------------------
 drivers/iio/light/isl29018.c   |  2 +-
 drivers/iio/light/ltr501.c     |  2 +-
 3 files changed, 8 insertions(+), 26 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#1 lore raw

PATCH v3 1/4 iio: light: isl29018: Assign NULL to ddata in isl29018_probe()

When iio_get_acpi_device_name_and_data() fails, the ddata may be left uninitialised. Initialise it to NULL.

Fixes 14686836fb69 ("iio: light: isl29018: Replace a variant of iio_get_acpi_device_name_and_data()")
---
 drivers/iio/light/isl29018.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/isl29018.c +1 -1
index cbe34026bda6..201eae1c4589 100644
@@ -703,7 +703,7 @@ static int isl29018_probe(struct i2c_client *client)
 	const struct i2c_device_id *id = i2c_client_get_device_id(client);
 	struct isl29018_chip *chip;
 	struct iio_dev *indio_dev;
-	const void *ddata;
+	const void *ddata = NULL;
 	const char *name;
 	int dev_id;
 	int err;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#2 lore raw

PATCH v3 2/4 iio: light: ltr501: Assign NULL to ddata in ltr501_probe()

In reply to Andy Shevchenko

When iio_get_acpi_device_name_and_data() fails, the ddata may be left uninitialised. Initialise it to NULL.

Fixes 61da460b813d ("iio: light: ltr501: Replace a variant of iio_get_acpi_device_name_and_data()")
---
 drivers/iio/light/ltr501.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/ltr501.c +1 -1
index 7228611d4c59..616dc6921702 100644
@@ -1424,8 +1424,8 @@ static int ltr501_probe(struct i2c_client *client)
 	struct ltr501_data *data;
 	struct iio_dev *indio_dev;
 	struct regmap *regmap;
+	const void *ddata = NULL;
 	int partid, chip_idx;
-	const void *ddata;
 	const char *name;
 	int ret;
 
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#3 lore raw

PATCH v3 3/4 iio: accel: kxcjk-1013: Assign NULL to ddata in kxcjk1013_probe()

In reply to Andy Shevchenko

When iio_get_acpi_device_name_and_data() fails, the ddata may be left uninitialised. Initialise it to NULL and drop unneeded NULL check in kxcjk1013_probe().

---
 drivers/iio/accel/kxcjk-1013.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/accel/kxcjk-1013.c +2 -3
index 28ed0e09d099..753ec2f71a9a 100644
@@ -1462,7 +1462,7 @@ static int kxcjk1013_probe(struct i2c_client *client)
 	struct kxcjk1013_data *data;
 	struct iio_dev *indio_dev;
 	struct kxcjk_1013_platform_data *pdata;
-	const void *ddata;
+	const void *ddata = NULL;
 	const char *name;
 	int ret;
 
@@ -1507,8 +1507,7 @@ static int kxcjk1013_probe(struct i2c_client *client)
 		data->info = (const struct kx_chipset_info *)(id->driver_data);
 	} else {
 		name = iio_get_acpi_device_name_and_data(&client->dev, &ddata);
-		if (name)
-			data->info = ddata;
+		data->info = ddata;
 		if (data->info == &kxcj91008_kiox010a_info)
 			indio_dev->label = "accel-display";
 		else if (data->info == &kxcj91008_kiox020a_info)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#4 lore raw

PATCH v3 4/4 iio: accel: kxcjk-1013: Deduplicate ODR startup time array

In reply to Andy Shevchenko

The content of kxcj91008_odr_start_up_times and kxcjk1013_odr_start_up_times is identical, deduplicate it.

---
 drivers/iio/accel/kxcjk-1013.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)
drivers/iio/accel/kxcjk-1013.c +4 -21
index 753ec2f71a9a..f65fde06f2c1 100644
@@ -193,23 +193,6 @@ static const struct kx_odr_start_up_time kxcjk1013_odr_start_up_times[] = {
 	{ }
 };
 
-/* KXCJ9-1008 */
-static const struct kx_odr_start_up_time kxcj91008_odr_start_up_times[] = {
-	{ 0x08, 100000 },
-	{ 0x09, 100000 },
-	{ 0x0A, 100000 },
-	{ 0x0B, 100000 },
-	{ 0x00, 80000 },
-	{ 0x01, 41000 },
-	{ 0x02, 21000 },
-	{ 0x03, 11000 },
-	{ 0x04, 6400 },
-	{ 0x05, 3900 },
-	{ 0x06, 2700 },
-	{ 0x07, 2100 },
-	{ }
-};
-
 /* KXCTJ2-1009 */
 static const struct kx_odr_start_up_time kxtj21009_odr_start_up_times[] = {
 	{ 0x08, 1240000 },
@@ -325,24 +308,24 @@ static const struct kx_chipset_info kxcjk1013_info = {
 
 static const struct kx_chipset_info kxcj91008_info = {
 	.regs = &kxcjk1013_regs,
-	.times = pm_ptr(kxcj91008_odr_start_up_times),
+	.times = pm_ptr(kxcjk1013_odr_start_up_times),
 };
 
 static const struct kx_chipset_info kxcj91008_kiox010a_info = {
 	.regs = &kxcjk1013_regs,
-	.times = pm_ptr(kxcj91008_odr_start_up_times),
+	.times = pm_ptr(kxcjk1013_odr_start_up_times),
 	.acpi_type = ACPI_KIOX010A,
 };
 
 static const struct kx_chipset_info kxcj91008_kiox020a_info = {
 	.regs = &kxcjk1013_regs,
-	.times = pm_ptr(kxcj91008_odr_start_up_times),
+	.times = pm_ptr(kxcjk1013_odr_start_up_times),
 	.acpi_type = ACPI_GENERIC,
 };
 
 static const struct kx_chipset_info kxcj91008_smo8500_info = {
 	.regs = &kxcjk1013_regs,
-	.times = pm_ptr(kxcj91008_odr_start_up_times),
+	.times = pm_ptr(kxcjk1013_odr_start_up_times),
 	.acpi_type = ACPI_SMO8500,
 };
 
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer
#5 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · On Fri, 1 Nov 2024 15:16:00 +0200 Andy Shevchenko…

Dan reported that ddata might be used uninitialised in some cases. Let's initialise it to NULL (patches 1 - 3). With that, update one driver to drop an unneeded anymore check (included in patch 3).

While at it, one more cleanup to kxcjk-1013 (patch 4) is added.

Jonathan, dunno if you want to rebase at this stage (probably not), but if you do, feel free to fold the patches 1-3 to the initial code.

Ah. I've just picked v2, but given I squashed anyway the commit message changes don't matter. I was curious what Assing meant but not need to ask given I wasn't going to keep it.

Jonathan

Quoted 18 lines

In v3:
- made Subject more specific for patches 1-3 (Markus)

In v2:
- rewritten patches 1-3 to do the job on the caller side (Jonathan)

Andy Shevchenko (4):
iio: light: isl29018: Assign NULL to ddata in isl29018_probe()
iio: light: ltr501: Assign NULL to ddata in ltr501_probe()
iio: accel: kxcjk-1013: Assign NULL to ddata in kxcjk1013_probe()
iio: accel: kxcjk-1013: Deduplicate ODR startup time array

 drivers/iio/accel/kxcjk-1013.c | 30 ++++++------------------------
 drivers/iio/light/isl29018.c   |  2 +-
 drivers/iio/light/ltr501.c     |  2 +-
 3 files changed, 8 insertions(+), 26 deletions(-)
#6 lore raw
Quoted 7 lines · Jonathan Cameron
Quoted 4 lines · On Fri, 1 Nov 2024 15:16:00 +0200 Andy Shevchenko…

Dan reported that ddata might be used uninitialised in some cases. Let's initialise it to NULL (patches 1 - 3). With that, update one driver to drop an unneeded anymore check (included in patch 3).

Quoted 6 lines
Quoted 4 lines

While at it, one more cleanup to kxcjk-1013 (patch 4) is added.

Jonathan, dunno if you want to rebase at this stage (probably not), but if you do, feel free to fold the patches 1-3 to the initial code.

Ah. I've just picked v2, but given I squashed anyway the commit message changes don't matter.

Thanks, I have looked into the resulting changes and it all LGTM!

Quoted 2 lines

I was curious what Assing meant but not need to
ask given I wasn't going to keep it.

He-he :-)

Signature · 2 lines
With Best Regards,
Andy Shevchenko