Merge branch 'remotes/lorenzo/pci/keembay'
[linux-2.6-microblaze.git] / drivers / pci / pci-label.c
index c32f3b7..0c64465 100644 (file)
@@ -139,14 +139,17 @@ enum acpi_attr_enum {
        ACPI_ATTR_INDEX_SHOW,
 };
 
-static void dsm_label_utf16s_to_utf8s(union acpi_object *obj, char *buf)
+static int dsm_label_utf16s_to_utf8s(union acpi_object *obj, char *buf)
 {
        int len;
+
        len = utf16s_to_utf8s((const wchar_t *)obj->buffer.pointer,
                              obj->buffer.length,
                              UTF16_LITTLE_ENDIAN,
-                             buf, PAGE_SIZE);
-       buf[len] = '\n';
+                             buf, PAGE_SIZE - 1);
+       buf[len++] = '\n';
+
+       return len;
 }
 
 static int dsm_get_label(struct device *dev, char *buf,
@@ -154,7 +157,7 @@ static int dsm_get_label(struct device *dev, char *buf,
 {
        acpi_handle handle = ACPI_HANDLE(dev);
        union acpi_object *obj, *tmp;
-       int len = -1;
+       int len = 0;
 
        if (!handle)
                return -1;
@@ -175,20 +178,19 @@ static int dsm_get_label(struct device *dev, char *buf,
                 * this entry must return a null string.
                 */
                if (attr == ACPI_ATTR_INDEX_SHOW) {
-                       scnprintf(buf, PAGE_SIZE, "%llu\n", tmp->integer.value);
+                       len = sysfs_emit(buf, "%llu\n", tmp->integer.value);
                } else if (attr == ACPI_ATTR_LABEL_SHOW) {
                        if (tmp[1].type == ACPI_TYPE_STRING)
-                               scnprintf(buf, PAGE_SIZE, "%s\n",
-                                         tmp[1].string.pointer);
+                               len = sysfs_emit(buf, "%s\n",
+                                                tmp[1].string.pointer);
                        else if (tmp[1].type == ACPI_TYPE_BUFFER)
-                               dsm_label_utf16s_to_utf8s(tmp + 1, buf);
+                               len = dsm_label_utf16s_to_utf8s(tmp + 1, buf);
                }
-               len = strlen(buf) > 0 ? strlen(buf) : -1;
        }
 
        ACPI_FREE(obj);
 
-       return len;
+       return len > 0 ? len : -1;
 }
 
 static ssize_t label_show(struct device *dev, struct device_attribute *attr,