Skip to contentSkip to conversation

iio: initialise ddata for iio_get_acpi_device_name_and_data()

PATCH Superseded Andy Shevchenko 3 participants 10 messages Nov 1, 2024 IIO

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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 v2:
- rewritten patches 1-3 to do the job on the caller side (Jonathan)

Andy Shevchenko (4):
iio: light: ltr501: Assing ddata to NULL
iio: light: isl29018: Assing ddata to NULL
iio: accel: kxcjk-1013: Assing ddata to NULL instead of NULL check
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 v2 1/4 iio: light: ltr501: Assing ddata to NULL

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
#2 lore raw

Re: [PATCH v2 1/4] iio: light: ltr501: Assing ddata to NULL

Quoted 2 lines

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

Would you like to use the summary phrase “Assign NULL to ddata in ltr501_probe()” accordingly?

Regards,
Markus

#3 lore raw

Re: [PATCH v2 1/4] iio: light: ltr501: Assing ddata to NULL

In reply to Andy Shevchenko
Quoted 2 lines

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

How do you think about to perform the variable assignment only in a corresponding else branch?

Can it be that this adjustment does not really matter here because of the following statement?

	if (!name)
		return -ENODEV;

Regards,
Markus

#4 lore raw

PATCH v2 2/4 iio: light: isl29018: Assing ddata to NULL

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 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
#5 lore raw

Re: [PATCH v2 2/4] iio: light: isl29018: Assing ddata to NULL

Quoted 2 lines

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

Would a summary phrase like “Assign NULL to ddata in isl29018_probe()” be helpful?

How do you think about a null pointer check also with the local variable “name” instead?

Regards,
Markus

#6 lore raw

PATCH v2 3/4 iio: accel: kxcjk-1013: Assing ddata to NULL instead of NULL check

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
#7 lore raw

Re: [PATCH v2 3/4] iio: accel: kxcjk-1013: Assing ddata to NULL instead of NULL check

Quoted 3 lines

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()

I propose to reduce the scope for this local variable.

How do you think about to use a summary phrase like “Replace a pointer check by a variable initialisation in kxcjk1013_probe()” instead?

Regards,
Markus

#8 lore raw

PATCH v2 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
#9 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · On Fri, 1 Nov 2024 10:08:25 +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.

I had to rebase anyway for another reason so given that squashed those 3 in.

4 is on top of the tree.

Thanks,

Jonathan

Quoted 15 lines

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

Andy Shevchenko (4):
iio: light: ltr501: Assing ddata to NULL
iio: light: isl29018: Assing ddata to NULL
iio: accel: kxcjk-1013: Assing ddata to NULL instead of NULL check
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(-)