Skip to content

Commit ab93048

Browse files
andy-shevrafaeljw
authored andcommitted
ACPI: property: Fix return value for nval == 0 in acpi_data_prop_read()
While analysing code for software and OF node for the corner case when caller asks to read zero items in the supposed to be an array of values I found that ACPI behaves differently to what OF does, i.e. 1. It returns -EINVAL when caller asks to read zero items from integer array, while OF returns 0, if no other errors happened. 2. It returns -EINVAL when caller asks to read zero items from string array, while OF returns -ENODATA, if no other errors happened. Amend ACPI implementation to follow what OF does. Fixes: b31384f ("Driver core: Unified device properties interface for platform firmware") Signed-off-by: Andy Shevchenko <[email protected]> Link: https://patch.msgid.link/[email protected] [ rjw: Added empty line after a conditional ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 2014c95 commit ab93048

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/acpi/property.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,6 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,
11871187
}
11881188
break;
11891189
}
1190-
if (nval == 0)
1191-
return -EINVAL;
11921190

11931191
if (obj->type == ACPI_TYPE_BUFFER) {
11941192
if (proptype != DEV_PROP_U8)
@@ -1212,9 +1210,11 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,
12121210
ret = acpi_copy_property_array_uint(items, (u64 *)val, nval);
12131211
break;
12141212
case DEV_PROP_STRING:
1215-
ret = acpi_copy_property_array_string(
1216-
items, (char **)val,
1217-
min_t(u32, nval, obj->package.count));
1213+
nval = min_t(u32, nval, obj->package.count);
1214+
if (nval == 0)
1215+
return -ENODATA;
1216+
1217+
ret = acpi_copy_property_array_string(items, (char **)val, nval);
12181218
break;
12191219
default:
12201220
ret = -EINVAL;

0 commit comments

Comments
 (0)