@@ -101,16 +101,15 @@ static bool cmd_db_magic_matches(const struct cmd_db_header *header)
101101
102102static struct cmd_db_header * cmd_db_header ;
103103
104-
105- static inline void * rsc_to_entry_header (struct rsc_hdr * hdr )
104+ static inline const void * rsc_to_entry_header (const struct rsc_hdr * hdr )
106105{
107106 u16 offset = le16_to_cpu (hdr -> header_offset );
108107
109108 return cmd_db_header -> data + offset ;
110109}
111110
112111static inline void *
113- rsc_offset (struct rsc_hdr * hdr , struct entry_header * ent )
112+ rsc_offset (const struct rsc_hdr * hdr , const struct entry_header * ent )
114113{
115114 u16 offset = le16_to_cpu (hdr -> data_offset );
116115 u16 loffset = le16_to_cpu (ent -> offset );
@@ -134,21 +133,18 @@ int cmd_db_ready(void)
134133}
135134EXPORT_SYMBOL (cmd_db_ready );
136135
137- static int cmd_db_get_header (const char * id , struct entry_header * eh ,
138- struct rsc_hdr * rh )
136+ static int cmd_db_get_header (const char * id , const struct entry_header * * eh ,
137+ const struct rsc_hdr * * rh )
139138{
140- struct rsc_hdr * rsc_hdr ;
141- struct entry_header * ent ;
139+ const struct rsc_hdr * rsc_hdr ;
140+ const struct entry_header * ent ;
142141 int ret , i , j ;
143142 u8 query [8 ];
144143
145144 ret = cmd_db_ready ();
146145 if (ret )
147146 return ret ;
148147
149- if (!eh || !rh )
150- return - EINVAL ;
151-
152148 /* Pad out query string to same length as in DB */
153149 strncpy (query , id , sizeof (query ));
154150
@@ -159,14 +155,13 @@ static int cmd_db_get_header(const char *id, struct entry_header *eh,
159155
160156 ent = rsc_to_entry_header (rsc_hdr );
161157 for (j = 0 ; j < le16_to_cpu (rsc_hdr -> cnt ); j ++ , ent ++ ) {
162- if (memcmp (ent -> id , query , sizeof (ent -> id )) == 0 )
163- break ;
164- }
165-
166- if (j < le16_to_cpu (rsc_hdr -> cnt )) {
167- memcpy (eh , ent , sizeof (* ent ));
168- memcpy (rh , rsc_hdr , sizeof (* rh ));
169- return 0 ;
158+ if (memcmp (ent -> id , query , sizeof (ent -> id )) == 0 ) {
159+ if (eh )
160+ * eh = ent ;
161+ if (rh )
162+ * rh = rsc_hdr ;
163+ return 0 ;
164+ }
170165 }
171166 }
172167
@@ -186,12 +181,11 @@ static int cmd_db_get_header(const char *id, struct entry_header *eh,
186181u32 cmd_db_read_addr (const char * id )
187182{
188183 int ret ;
189- struct entry_header ent ;
190- struct rsc_hdr rsc_hdr ;
184+ const struct entry_header * ent ;
191185
192- ret = cmd_db_get_header (id , & ent , & rsc_hdr );
186+ ret = cmd_db_get_header (id , & ent , NULL );
193187
194- return ret < 0 ? 0 : le32_to_cpu (ent . addr );
188+ return ret < 0 ? 0 : le32_to_cpu (ent -> addr );
195189}
196190EXPORT_SYMBOL (cmd_db_read_addr );
197191
@@ -207,8 +201,8 @@ EXPORT_SYMBOL(cmd_db_read_addr);
207201int cmd_db_read_aux_data (const char * id , u8 * data , size_t len )
208202{
209203 int ret ;
210- struct entry_header ent ;
211- struct rsc_hdr rsc_hdr ;
204+ const struct entry_header * ent ;
205+ const struct rsc_hdr * rsc_hdr ;
212206 u16 ent_len ;
213207
214208 if (!data )
@@ -218,12 +212,12 @@ int cmd_db_read_aux_data(const char *id, u8 *data, size_t len)
218212 if (ret )
219213 return ret ;
220214
221- ent_len = le16_to_cpu (ent . len );
215+ ent_len = le16_to_cpu (ent -> len );
222216 if (len < ent_len )
223217 return - EINVAL ;
224218
225219 len = min_t (u16 , ent_len , len );
226- memcpy (data , rsc_offset (& rsc_hdr , & ent ), len );
220+ memcpy (data , rsc_offset (rsc_hdr , ent ), len );
227221
228222 return len ;
229223}
@@ -239,12 +233,11 @@ EXPORT_SYMBOL(cmd_db_read_aux_data);
239233size_t cmd_db_read_aux_data_len (const char * id )
240234{
241235 int ret ;
242- struct entry_header ent ;
243- struct rsc_hdr rsc_hdr ;
236+ const struct entry_header * ent ;
244237
245- ret = cmd_db_get_header (id , & ent , & rsc_hdr );
238+ ret = cmd_db_get_header (id , & ent , NULL );
246239
247- return ret < 0 ? 0 : le16_to_cpu (ent . len );
240+ return ret < 0 ? 0 : le16_to_cpu (ent -> len );
248241}
249242EXPORT_SYMBOL (cmd_db_read_aux_data_len );
250243
@@ -258,15 +251,14 @@ EXPORT_SYMBOL(cmd_db_read_aux_data_len);
258251enum cmd_db_hw_type cmd_db_read_slave_id (const char * id )
259252{
260253 int ret ;
261- struct entry_header ent ;
262- struct rsc_hdr rsc_hdr ;
254+ const struct entry_header * ent ;
263255 u32 addr ;
264256
265- ret = cmd_db_get_header (id , & ent , & rsc_hdr );
257+ ret = cmd_db_get_header (id , & ent , NULL );
266258 if (ret < 0 )
267259 return CMD_DB_HW_INVALID ;
268260
269- addr = le32_to_cpu (ent . addr );
261+ addr = le32_to_cpu (ent -> addr );
270262 return (addr >> SLAVE_ID_SHIFT ) & SLAVE_ID_MASK ;
271263}
272264EXPORT_SYMBOL (cmd_db_read_slave_id );
0 commit comments