10
10
11
11
#include <linux/acpi.h>
12
12
#include <linux/byteorder/generic.h>
13
+ #include <linux/cleanup.h>
13
14
#include <linux/device.h>
14
15
#include <linux/dev_printk.h>
15
16
#include <linux/module.h>
@@ -186,14 +187,18 @@ void sdca_lookup_functions(struct sdw_slave *slave)
186
187
}
187
188
EXPORT_SYMBOL_NS (sdca_lookup_functions , "SND_SOC_SDCA" );
188
189
190
+ struct raw_init_write {
191
+ __le32 addr ;
192
+ u8 val ;
193
+ } __packed ;
194
+
189
195
static int find_sdca_init_table (struct device * dev ,
190
196
struct fwnode_handle * function_node ,
191
197
struct sdca_function_data * function )
192
198
{
199
+ struct raw_init_write * raw __free (kfree ) = NULL ;
193
200
struct sdca_init_write * init_write ;
194
- int write_size = sizeof (init_write -> addr ) + sizeof (init_write -> val );
195
- u8 * init_list , * init_iter ;
196
- int num_init_writes ;
201
+ int i , num_init_writes ;
197
202
198
203
num_init_writes = fwnode_property_count_u8 (function_node ,
199
204
"mipi-sdca-function-initialization-table" );
@@ -203,41 +208,35 @@ static int find_sdca_init_table(struct device *dev,
203
208
dev_err (dev , "%pfwP: failed to read initialization table: %d\n" ,
204
209
function_node , num_init_writes );
205
210
return num_init_writes ;
206
- } else if (num_init_writes % write_size != 0 ) {
211
+ } else if (num_init_writes % sizeof ( * raw ) != 0 ) {
207
212
dev_err (dev , "%pfwP: init table size invalid\n" , function_node );
208
213
return - EINVAL ;
209
214
} else if (num_init_writes > SDCA_MAX_INIT_COUNT ) {
210
215
dev_err (dev , "%pfwP: maximum init table size exceeded\n" , function_node );
211
216
return - EINVAL ;
212
217
}
213
218
214
- init_write = devm_kcalloc (dev , num_init_writes / write_size ,
215
- sizeof (* init_write ), GFP_KERNEL );
216
- if (!init_write )
217
- return - ENOMEM ;
218
-
219
- init_list = kcalloc (num_init_writes , sizeof (* init_list ), GFP_KERNEL );
220
- if (!init_list )
219
+ raw = kzalloc (num_init_writes , GFP_KERNEL );
220
+ if (!raw )
221
221
return - ENOMEM ;
222
222
223
223
fwnode_property_read_u8_array (function_node ,
224
224
"mipi-sdca-function-initialization-table" ,
225
- init_list , num_init_writes );
225
+ ( u8 * ) raw , num_init_writes );
226
226
227
- function -> num_init_table = num_init_writes ;
228
- function -> init_table = init_write ;
227
+ num_init_writes /= sizeof (* raw );
229
228
230
- for (init_iter = init_list ; init_iter < init_list + num_init_writes ;) {
231
- u32 * addr = (u32 * )init_iter ;
232
-
233
- init_write -> addr = le32_to_cpu (* addr );
234
- init_iter += sizeof (init_write -> addr );
229
+ init_write = devm_kcalloc (dev , num_init_writes , sizeof (* init_write ), GFP_KERNEL );
230
+ if (!init_write )
231
+ return - ENOMEM ;
235
232
236
- init_write -> val = * init_iter ;
237
- init_iter += sizeof (init_write -> val );
233
+ for (i = 0 ; i < num_init_writes ; i ++ ) {
234
+ init_write [i ].addr = le32_to_cpu (raw [i ].addr );
235
+ init_write [i ].val = raw [i ].val ;
238
236
}
239
237
240
- kfree (init_list );
238
+ function -> num_init_table = num_init_writes ;
239
+ function -> init_table = init_write ;
241
240
242
241
return 0 ;
243
242
}
0 commit comments