Commit 3c2c58cb authored by Stefan Richter's avatar Stefan Richter

firewire: core: fw_csr_string addendum

Witespace and comment changes, and a different way to say i + 1 < end.
Signed-off-by: default avatarStefan Richter <stefanr@s5r6.in-berlin.de>
parent 1f8fef7b
...@@ -69,19 +69,22 @@ static u32 *search_leaf(u32 *directory, int search_key) ...@@ -69,19 +69,22 @@ static u32 *search_leaf(u32 *directory, int search_key)
if (last_key == search_key && if (last_key == search_key &&
key == (CSR_DESCRIPTOR | CSR_LEAF)) key == (CSR_DESCRIPTOR | CSR_LEAF))
return ci.p - 1 + value; return ci.p - 1 + value;
last_key = key; last_key = key;
} }
return NULL; return NULL;
} }
static int textual_leaf_to_string(u32 *block, char *buf, size_t size) static int textual_leaf_to_string(u32 *block, char *buf, size_t size)
{ {
unsigned int quadlets, length; unsigned int quadlets, i;
char c;
if (!size || !buf) if (!size || !buf)
return -EINVAL; return -EINVAL;
quadlets = min(block[0] >> 16, 256u); quadlets = min(block[0] >> 16, 256U);
if (quadlets < 2) if (quadlets < 2)
return -ENODATA; return -ENODATA;
...@@ -91,31 +94,34 @@ static int textual_leaf_to_string(u32 *block, char *buf, size_t size) ...@@ -91,31 +94,34 @@ static int textual_leaf_to_string(u32 *block, char *buf, size_t size)
block += 3; block += 3;
quadlets -= 2; quadlets -= 2;
for (length = 0; length < quadlets * 4 && length + 1 < size; length++) { for (i = 0; i < quadlets * 4 && i < size - 1; i++) {
char c = block[length / 4] >> (24 - 8 * (length % 4)); c = block[i / 4] >> (24 - 8 * (i % 4));
if (c == '\0') if (c == '\0')
break; break;
buf[length] = c; buf[i] = c;
} }
buf[length] = '\0'; buf[i] = '\0';
return length;
return i;
} }
/** /**
* fw_csr_string - reads a string from the configuration ROM * fw_csr_string - reads a string from the configuration ROM
* @directory: device or unit directory; * @directory: e.g. root directory or unit directory
* fw_device->config_rom+5 or fw_unit->directory
* @key: the key of the preceding directory entry * @key: the key of the preceding directory entry
* @buf: where to put the string * @buf: where to put the string
* @size: size of @buf, in bytes * @size: size of @buf, in bytes
* *
* Returns string length (>= 0) or error code (< 0). * The string is taken from a minimal ASCII text descriptor leaf after
* the immediate entry with @key. The string is zero-terminated.
* Returns strlen(buf) or a negative error code.
*/ */
int fw_csr_string(u32 *directory, int key, char *buf, size_t size) int fw_csr_string(u32 *directory, int key, char *buf, size_t size)
{ {
u32 *leaf = search_leaf(directory, key); u32 *leaf = search_leaf(directory, key);
if (!leaf) if (!leaf)
return -ENOENT; return -ENOENT;
return textual_leaf_to_string(leaf, buf, size); return textual_leaf_to_string(leaf, buf, size);
} }
EXPORT_SYMBOL(fw_csr_string); EXPORT_SYMBOL(fw_csr_string);
......
...@@ -71,7 +71,6 @@ struct fw_csr_iterator { ...@@ -71,7 +71,6 @@ struct fw_csr_iterator {
void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p); void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value); int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value);
int fw_csr_string(u32 *directory, int key, char *buf, size_t size); int fw_csr_string(u32 *directory, int key, char *buf, size_t size);
extern struct bus_type fw_bus_type; extern struct bus_type fw_bus_type;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment