Skip to content

Commit 3c2c58c

Browse files
author
Stefan Richter
committed
firewire: core: fw_csr_string addendum
Witespace and comment changes, and a different way to say i + 1 < end. Signed-off-by: Stefan Richter <[email protected]>
1 parent 1f8fef7 commit 3c2c58c

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

drivers/firewire/core-device.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,22 @@ static u32 *search_leaf(u32 *directory, int search_key)
6969
if (last_key == search_key &&
7070
key == (CSR_DESCRIPTOR | CSR_LEAF))
7171
return ci.p - 1 + value;
72+
7273
last_key = key;
7374
}
75+
7476
return NULL;
7577
}
7678

7779
static int textual_leaf_to_string(u32 *block, char *buf, size_t size)
7880
{
79-
unsigned int quadlets, length;
81+
unsigned int quadlets, i;
82+
char c;
8083

8184
if (!size || !buf)
8285
return -EINVAL;
8386

84-
quadlets = min(block[0] >> 16, 256u);
87+
quadlets = min(block[0] >> 16, 256U);
8588
if (quadlets < 2)
8689
return -ENODATA;
8790

@@ -91,31 +94,34 @@ static int textual_leaf_to_string(u32 *block, char *buf, size_t size)
9194

9295
block += 3;
9396
quadlets -= 2;
94-
for (length = 0; length < quadlets * 4 && length + 1 < size; length++) {
95-
char c = block[length / 4] >> (24 - 8 * (length % 4));
97+
for (i = 0; i < quadlets * 4 && i < size - 1; i++) {
98+
c = block[i / 4] >> (24 - 8 * (i % 4));
9699
if (c == '\0')
97100
break;
98-
buf[length] = c;
101+
buf[i] = c;
99102
}
100-
buf[length] = '\0';
101-
return length;
103+
buf[i] = '\0';
104+
105+
return i;
102106
}
103107

104108
/**
105109
* fw_csr_string - reads a string from the configuration ROM
106-
* @directory: device or unit directory;
107-
* fw_device->config_rom+5 or fw_unit->directory
110+
* @directory: e.g. root directory or unit directory
108111
* @key: the key of the preceding directory entry
109112
* @buf: where to put the string
110113
* @size: size of @buf, in bytes
111114
*
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.
113118
*/
114119
int fw_csr_string(u32 *directory, int key, char *buf, size_t size)
115120
{
116121
u32 *leaf = search_leaf(directory, key);
117122
if (!leaf)
118123
return -ENOENT;
124+
119125
return textual_leaf_to_string(leaf, buf, size);
120126
}
121127
EXPORT_SYMBOL(fw_csr_string);

include/linux/firewire.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ struct fw_csr_iterator {
7171

7272
void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
7373
int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value);
74-
7574
int fw_csr_string(u32 *directory, int key, char *buf, size_t size);
7675

7776
extern struct bus_type fw_bus_type;

0 commit comments

Comments
 (0)