aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firewire
diff options
context:
space:
mode:
authorStefan Richter <stefanr@s5r6.in-berlin.de>2009-12-25 19:43:21 -0500
committerStefan Richter <stefanr@s5r6.in-berlin.de>2009-12-29 13:58:17 -0500
commit3c2c58cb33b3b15a2c4871babeec8fe1456e1db6 (patch)
treec19f59e4de0d9fb84fa5e4a7b3cd4d600d3708cd /drivers/firewire
parent1f8fef7b3388b5a976e80839679b5bae581a1091 (diff)
firewire: core: fw_csr_string addendum
Witespace and comment changes, and a different way to say i + 1 < end. Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers/firewire')
-rw-r--r--drivers/firewire/core-device.c26
1 files changed, 16 insertions, 10 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
77static int textual_leaf_to_string(u32 *block, char *buf, size_t size) 79static 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 */
114int fw_csr_string(u32 *directory, int key, char *buf, size_t size) 119int 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}
121EXPORT_SYMBOL(fw_csr_string); 127EXPORT_SYMBOL(fw_csr_string);