diff options
| -rw-r--r-- | drivers/firewire/core-device.c | 26 | ||||
| -rw-r--r-- | include/linux/firewire.h | 1 |
2 files changed, 16 insertions, 11 deletions
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c index a39e4344cd58..5d5c6a689837 100644 --- a/drivers/firewire/core-device.c +++ b/drivers/firewire/core-device.c | |||
| @@ -69,19 +69,22 @@ static u32 *search_leaf(u32 *directory, int search_key) | |||
| 69 | if (last_key == search_key && | 69 | if (last_key == search_key && |
| 70 | key == (CSR_DESCRIPTOR | CSR_LEAF)) | 70 | key == (CSR_DESCRIPTOR | CSR_LEAF)) |
| 71 | return ci.p - 1 + value; | 71 | return ci.p - 1 + value; |
| 72 | |||
| 72 | last_key = key; | 73 | last_key = key; |
| 73 | } | 74 | } |
| 75 | |||
| 74 | return NULL; | 76 | return NULL; |
| 75 | } | 77 | } |
| 76 | 78 | ||
| 77 | static int textual_leaf_to_string(u32 *block, char *buf, size_t size) | 79 | static int textual_leaf_to_string(u32 *block, char *buf, size_t size) |
| 78 | { | 80 | { |
| 79 | unsigned int quadlets, length; | 81 | unsigned int quadlets, i; |
| 82 | char c; | ||
| 80 | 83 | ||
| 81 | if (!size || !buf) | 84 | if (!size || !buf) |
| 82 | return -EINVAL; | 85 | return -EINVAL; |
| 83 | 86 | ||
| 84 | quadlets = min(block[0] >> 16, 256u); | 87 | quadlets = min(block[0] >> 16, 256U); |
| 85 | if (quadlets < 2) | 88 | if (quadlets < 2) |
| 86 | return -ENODATA; | 89 | return -ENODATA; |
| 87 | 90 | ||
| @@ -91,31 +94,34 @@ static int textual_leaf_to_string(u32 *block, char *buf, size_t size) | |||
| 91 | 94 | ||
| 92 | block += 3; | 95 | block += 3; |
| 93 | quadlets -= 2; | 96 | quadlets -= 2; |
| 94 | for (length = 0; length < quadlets * 4 && length + 1 < size; length++) { | 97 | for (i = 0; i < quadlets * 4 && i < size - 1; i++) { |
| 95 | char c = block[length / 4] >> (24 - 8 * (length % 4)); | 98 | c = block[i / 4] >> (24 - 8 * (i % 4)); |
| 96 | if (c == '\0') | 99 | if (c == '\0') |
| 97 | break; | 100 | break; |
| 98 | buf[length] = c; | 101 | buf[i] = c; |
| 99 | } | 102 | } |
| 100 | buf[length] = '\0'; | 103 | buf[i] = '\0'; |
| 101 | return length; | 104 | |
| 105 | return i; | ||
| 102 | } | 106 | } |
| 103 | 107 | ||
| 104 | /** | 108 | /** |
| 105 | * fw_csr_string - reads a string from the configuration ROM | 109 | * fw_csr_string - reads a string from the configuration ROM |
| 106 | * @directory: device or unit directory; | 110 | * @directory: e.g. root directory or unit directory |
| 107 | * fw_device->config_rom+5 or fw_unit->directory | ||
| 108 | * @key: the key of the preceding directory entry | 111 | * @key: the key of the preceding directory entry |
| 109 | * @buf: where to put the string | 112 | * @buf: where to put the string |
| 110 | * @size: size of @buf, in bytes | 113 | * @size: size of @buf, in bytes |
| 111 | * | 114 | * |
| 112 | * Returns string length (>= 0) or error code (< 0). | 115 | * The string is taken from a minimal ASCII text descriptor leaf after |
| 116 | * the immediate entry with @key. The string is zero-terminated. | ||
| 117 | * Returns strlen(buf) or a negative error code. | ||
| 113 | */ | 118 | */ |
| 114 | int fw_csr_string(u32 *directory, int key, char *buf, size_t size) | 119 | int fw_csr_string(u32 *directory, int key, char *buf, size_t size) |
| 115 | { | 120 | { |
| 116 | u32 *leaf = search_leaf(directory, key); | 121 | u32 *leaf = search_leaf(directory, key); |
| 117 | if (!leaf) | 122 | if (!leaf) |
| 118 | return -ENOENT; | 123 | return -ENOENT; |
| 124 | |||
| 119 | return textual_leaf_to_string(leaf, buf, size); | 125 | return textual_leaf_to_string(leaf, buf, size); |
| 120 | } | 126 | } |
| 121 | EXPORT_SYMBOL(fw_csr_string); | 127 | EXPORT_SYMBOL(fw_csr_string); |
diff --git a/include/linux/firewire.h b/include/linux/firewire.h index 5246869d8083..df680216e7b6 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h | |||
| @@ -71,7 +71,6 @@ struct fw_csr_iterator { | |||
| 71 | 71 | ||
| 72 | void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p); | 72 | void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p); |
| 73 | int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value); | 73 | int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value); |
| 74 | |||
| 75 | int fw_csr_string(u32 *directory, int key, char *buf, size_t size); | 74 | int fw_csr_string(u32 *directory, int key, char *buf, size_t size); |
| 76 | 75 | ||
| 77 | extern struct bus_type fw_bus_type; | 76 | extern struct bus_type fw_bus_type; |
