diff options
author | Zhang Rui <rui.zhang@intel.com> | 2014-01-14 03:46:35 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-01-16 17:06:42 -0500 |
commit | 3d8e00909df96c2d3eace3996748be9c0a437e5a (patch) | |
tree | 97baef1d748eb49d303772026143d10b56652bdf /drivers/acpi | |
parent | 7e22e91102c6b9df7c4ae2168910e19d2bb14cd6 (diff) |
ACPI: fix create_modalias() return value handling
Currently, create_modalias() handles the output truncated case in
an improper way (return -EINVAL).
Plus, acpi_device_uevent() and acpi_device_modalias_show() do
improper check for the create_modalias() return value as well.
This patch fixes create_modalias() to
return -EINVAL if there is an output error,
return -ENOMEM if the output is truncated,
and also fixes both acpi_device_uevent() and acpi_device_modalias_show()
to do proper return value check.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/scan.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index fd39459926b1..c92532158195 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -85,6 +85,9 @@ int acpi_scan_add_handler_with_hotplug(struct acpi_scan_handler *handler, | |||
85 | * Creates hid/cid(s) string needed for modalias and uevent | 85 | * Creates hid/cid(s) string needed for modalias and uevent |
86 | * e.g. on a device with hid:IBM0001 and cid:ACPI0001 you get: | 86 | * e.g. on a device with hid:IBM0001 and cid:ACPI0001 you get: |
87 | * char *modalias: "acpi:IBM0001:ACPI0001" | 87 | * char *modalias: "acpi:IBM0001:ACPI0001" |
88 | * Return: 0: no _HID and no _CID | ||
89 | * -EINVAL: output error | ||
90 | * -ENOMEM: output is truncated | ||
88 | */ | 91 | */ |
89 | static int create_modalias(struct acpi_device *acpi_dev, char *modalias, | 92 | static int create_modalias(struct acpi_device *acpi_dev, char *modalias, |
90 | int size) | 93 | int size) |
@@ -101,8 +104,10 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias, | |||
101 | 104 | ||
102 | list_for_each_entry(id, &acpi_dev->pnp.ids, list) { | 105 | list_for_each_entry(id, &acpi_dev->pnp.ids, list) { |
103 | count = snprintf(&modalias[len], size, "%s:", id->id); | 106 | count = snprintf(&modalias[len], size, "%s:", id->id); |
104 | if (count < 0 || count >= size) | 107 | if (count < 0) |
105 | return -EINVAL; | 108 | return EINVAL; |
109 | if (count >= size) | ||
110 | return -ENOMEM; | ||
106 | len += count; | 111 | len += count; |
107 | size -= count; | 112 | size -= count; |
108 | } | 113 | } |
@@ -116,10 +121,9 @@ acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, cha | |||
116 | struct acpi_device *acpi_dev = to_acpi_device(dev); | 121 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
117 | int len; | 122 | int len; |
118 | 123 | ||
119 | /* Device has no HID and no CID or string is >1024 */ | ||
120 | len = create_modalias(acpi_dev, buf, 1024); | 124 | len = create_modalias(acpi_dev, buf, 1024); |
121 | if (len <= 0) | 125 | if (len <= 0) |
122 | return 0; | 126 | return len; |
123 | buf[len++] = '\n'; | 127 | buf[len++] = '\n'; |
124 | return len; | 128 | return len; |
125 | } | 129 | } |
@@ -782,8 +786,8 @@ static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
782 | return -ENOMEM; | 786 | return -ENOMEM; |
783 | len = create_modalias(acpi_dev, &env->buf[env->buflen - 1], | 787 | len = create_modalias(acpi_dev, &env->buf[env->buflen - 1], |
784 | sizeof(env->buf) - env->buflen); | 788 | sizeof(env->buf) - env->buflen); |
785 | if (len >= (sizeof(env->buf) - env->buflen)) | 789 | if (len <= 0) |
786 | return -ENOMEM; | 790 | return len; |
787 | env->buflen += len; | 791 | env->buflen += len; |
788 | return 0; | 792 | return 0; |
789 | } | 793 | } |