Skip to content

Commit 988adcb

Browse files
charleskeepaxbroonie
authored andcommitted
ASoC: SDCA: Tidy up initialization write parsing
Slightly neaten up the initialization write code to overlay a struct rather than shifting the pointer along manually. This also removes the Sparse warning: sound/soc/sdca/sdca_functions.c:233:36: warning: cast to restricted __le32 Signed-off-by: Charles Keepax <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent d9a0693 commit 988adcb

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

sound/soc/sdca/sdca_functions.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <linux/acpi.h>
1212
#include <linux/byteorder/generic.h>
13+
#include <linux/cleanup.h>
1314
#include <linux/device.h>
1415
#include <linux/dev_printk.h>
1516
#include <linux/module.h>
@@ -186,14 +187,18 @@ void sdca_lookup_functions(struct sdw_slave *slave)
186187
}
187188
EXPORT_SYMBOL_NS(sdca_lookup_functions, "SND_SOC_SDCA");
188189

190+
struct raw_init_write {
191+
__le32 addr;
192+
u8 val;
193+
} __packed;
194+
189195
static int find_sdca_init_table(struct device *dev,
190196
struct fwnode_handle *function_node,
191197
struct sdca_function_data *function)
192198
{
199+
struct raw_init_write *raw __free(kfree) = NULL;
193200
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;
197202

198203
num_init_writes = fwnode_property_count_u8(function_node,
199204
"mipi-sdca-function-initialization-table");
@@ -203,41 +208,35 @@ static int find_sdca_init_table(struct device *dev,
203208
dev_err(dev, "%pfwP: failed to read initialization table: %d\n",
204209
function_node, num_init_writes);
205210
return num_init_writes;
206-
} else if (num_init_writes % write_size != 0) {
211+
} else if (num_init_writes % sizeof(*raw) != 0) {
207212
dev_err(dev, "%pfwP: init table size invalid\n", function_node);
208213
return -EINVAL;
209214
} else if (num_init_writes > SDCA_MAX_INIT_COUNT) {
210215
dev_err(dev, "%pfwP: maximum init table size exceeded\n", function_node);
211216
return -EINVAL;
212217
}
213218

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)
221221
return -ENOMEM;
222222

223223
fwnode_property_read_u8_array(function_node,
224224
"mipi-sdca-function-initialization-table",
225-
init_list, num_init_writes);
225+
(u8 *)raw, num_init_writes);
226226

227-
function->num_init_table = num_init_writes;
228-
function->init_table = init_write;
227+
num_init_writes /= sizeof(*raw);
229228

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;
235232

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;
238236
}
239237

240-
kfree(init_list);
238+
function->num_init_table = num_init_writes;
239+
function->init_table = init_write;
241240

242241
return 0;
243242
}

0 commit comments

Comments
 (0)