@@ -69,19 +69,22 @@ static u32 *search_leaf(u32 *directory, int search_key)
69
69
if (last_key == search_key &&
70
70
key == (CSR_DESCRIPTOR | CSR_LEAF ))
71
71
return ci .p - 1 + value ;
72
+
72
73
last_key = key ;
73
74
}
75
+
74
76
return NULL ;
75
77
}
76
78
77
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
84
if (!size || !buf )
82
85
return - EINVAL ;
83
86
84
- quadlets = min (block [0 ] >> 16 , 256u );
87
+ quadlets = min (block [0 ] >> 16 , 256U );
85
88
if (quadlets < 2 )
86
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
95
block += 3 ;
93
96
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 ));
96
99
if (c == '\0' )
97
100
break ;
98
- buf [length ] = c ;
101
+ buf [i ] = c ;
99
102
}
100
- buf [length ] = '\0' ;
101
- return length ;
103
+ buf [i ] = '\0' ;
104
+
105
+ return i ;
102
106
}
103
107
104
108
/**
105
109
* 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
108
111
* @key: the key of the preceding directory entry
109
112
* @buf: where to put the string
110
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
119
int fw_csr_string (u32 * directory , int key , char * buf , size_t size )
115
120
{
116
121
u32 * leaf = search_leaf (directory , key );
117
122
if (!leaf )
118
123
return - ENOENT ;
124
+
119
125
return textual_leaf_to_string (leaf , buf , size );
120
126
}
121
127
EXPORT_SYMBOL (fw_csr_string );
0 commit comments