Skip to content

Commit d0f4ce8

Browse files
krzkbroonie
authored andcommitted
ASoC: codecs: aw88395: Simplify with cleanup.h
Allocate memory, which is being freed at end of the scope, with scoped/cleanup.h to reduce number of error paths and make code a bit simpler. Signed-off-by: Krzysztof Kozlowski <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent e52a73e commit d0f4ce8

File tree

1 file changed

+17
-34
lines changed

1 file changed

+17
-34
lines changed

sound/soc/codecs/aw88395/aw88395_lib.c

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// Author: Bruce zhao <[email protected]>
88
//
99

10+
#include <linux/cleanup.h>
1011
#include <linux/crc8.h>
1112
#include <linux/i2c.h>
1213
#include "aw88395_lib.h"
@@ -361,11 +362,11 @@ static int aw_dev_parse_raw_dsp_fw(unsigned char *data, unsigned int data_len,
361362
static int aw_dev_prof_parse_multi_bin(struct aw_device *aw_dev, unsigned char *data,
362363
unsigned int data_len, struct aw_prof_desc *prof_desc)
363364
{
364-
struct aw_bin *aw_bin;
365365
int ret;
366366
int i;
367367

368-
aw_bin = devm_kzalloc(aw_dev->dev, data_len + sizeof(struct aw_bin), GFP_KERNEL);
368+
struct aw_bin *aw_bin __free(kfree) = kzalloc(data_len + sizeof(struct aw_bin),
369+
GFP_KERNEL);
369370
if (!aw_bin)
370371
return -ENOMEM;
371372

@@ -375,7 +376,7 @@ static int aw_dev_prof_parse_multi_bin(struct aw_device *aw_dev, unsigned char *
375376
ret = aw_parsing_bin_file(aw_dev, aw_bin);
376377
if (ret < 0) {
377378
dev_err(aw_dev->dev, "parse bin failed");
378-
goto parse_bin_failed;
379+
return ret;
379380
}
380381

381382
for (i = 0; i < aw_bin->all_bin_parse_num; i++) {
@@ -387,10 +388,8 @@ static int aw_dev_prof_parse_multi_bin(struct aw_device *aw_dev, unsigned char *
387388
data + aw_bin->header_info[i].valid_data_addr;
388389
break;
389390
case DATA_TYPE_DSP_REG:
390-
if (aw_bin->header_info[i].valid_data_len & 0x01) {
391-
ret = -EINVAL;
392-
goto parse_bin_failed;
393-
}
391+
if (aw_bin->header_info[i].valid_data_len & 0x01)
392+
return -EINVAL;
394393

395394
swab16_array((u16 *)(data + aw_bin->header_info[i].valid_data_addr),
396395
aw_bin->header_info[i].valid_data_len >> 1);
@@ -402,10 +401,8 @@ static int aw_dev_prof_parse_multi_bin(struct aw_device *aw_dev, unsigned char *
402401
break;
403402
case DATA_TYPE_DSP_FW:
404403
case DATA_TYPE_SOC_APP:
405-
if (aw_bin->header_info[i].valid_data_len & 0x01) {
406-
ret = -EINVAL;
407-
goto parse_bin_failed;
408-
}
404+
if (aw_bin->header_info[i].valid_data_len & 0x01)
405+
return -EINVAL;
409406

410407
swab16_array((u16 *)(data + aw_bin->header_info[i].valid_data_addr),
411408
aw_bin->header_info[i].valid_data_len >> 1);
@@ -422,20 +419,17 @@ static int aw_dev_prof_parse_multi_bin(struct aw_device *aw_dev, unsigned char *
422419
}
423420
}
424421
prof_desc->prof_st = AW88395_PROFILE_OK;
425-
ret = 0;
426422

427-
parse_bin_failed:
428-
devm_kfree(aw_dev->dev, aw_bin);
429-
return ret;
423+
return 0;
430424
}
431425

432426
static int aw_dev_parse_reg_bin_with_hdr(struct aw_device *aw_dev,
433427
uint8_t *data, uint32_t data_len, struct aw_prof_desc *prof_desc)
434428
{
435-
struct aw_bin *aw_bin;
436429
int ret;
437430

438-
aw_bin = devm_kzalloc(aw_dev->dev, data_len + sizeof(*aw_bin), GFP_KERNEL);
431+
struct aw_bin *aw_bin __free(kfree) = kzalloc(data_len + sizeof(*aw_bin),
432+
GFP_KERNEL);
439433
if (!aw_bin)
440434
return -ENOMEM;
441435

@@ -445,14 +439,13 @@ static int aw_dev_parse_reg_bin_with_hdr(struct aw_device *aw_dev,
445439
ret = aw_parsing_bin_file(aw_dev, aw_bin);
446440
if (ret < 0) {
447441
dev_err(aw_dev->dev, "parse bin failed");
448-
goto parse_bin_failed;
442+
return ret;
449443
}
450444

451445
if ((aw_bin->all_bin_parse_num != 1) ||
452446
(aw_bin->header_info[0].bin_data_type != DATA_TYPE_REGISTER)) {
453447
dev_err(aw_dev->dev, "bin num or type error");
454-
ret = -EINVAL;
455-
goto parse_bin_failed;
448+
return -EINVAL;
456449
}
457450

458451
prof_desc->sec_desc[AW88395_DATA_TYPE_REG].data =
@@ -461,15 +454,7 @@ static int aw_dev_parse_reg_bin_with_hdr(struct aw_device *aw_dev,
461454
aw_bin->header_info[0].valid_data_len;
462455
prof_desc->prof_st = AW88395_PROFILE_OK;
463456

464-
devm_kfree(aw_dev->dev, aw_bin);
465-
aw_bin = NULL;
466-
467457
return 0;
468-
469-
parse_bin_failed:
470-
devm_kfree(aw_dev->dev, aw_bin);
471-
aw_bin = NULL;
472-
return ret;
473458
}
474459

475460
static int aw_dev_parse_data_by_sec_type(struct aw_device *aw_dev, struct aw_cfg_hdr *cfg_hdr,
@@ -678,21 +663,21 @@ static int aw_dev_cfg_get_multiple_valid_prof(struct aw_device *aw_dev,
678663
static int aw_dev_load_cfg_by_hdr(struct aw_device *aw_dev,
679664
struct aw_cfg_hdr *prof_hdr)
680665
{
681-
struct aw_all_prof_info *all_prof_info;
682666
int ret;
683667

684-
all_prof_info = devm_kzalloc(aw_dev->dev, sizeof(struct aw_all_prof_info), GFP_KERNEL);
668+
struct aw_all_prof_info *all_prof_info __free(kfree) = kzalloc(sizeof(*all_prof_info),
669+
GFP_KERNEL);
685670
if (!all_prof_info)
686671
return -ENOMEM;
687672

688673
ret = aw_dev_parse_dev_type(aw_dev, prof_hdr, all_prof_info);
689674
if (ret < 0) {
690-
goto exit;
675+
return ret;
691676
} else if (ret == AW88395_DEV_TYPE_NONE) {
692677
dev_dbg(aw_dev->dev, "get dev type num is 0, parse default dev");
693678
ret = aw_dev_parse_dev_default_type(aw_dev, prof_hdr, all_prof_info);
694679
if (ret < 0)
695-
goto exit;
680+
return ret;
696681
}
697682

698683
switch (aw_dev->prof_data_type) {
@@ -710,8 +695,6 @@ static int aw_dev_load_cfg_by_hdr(struct aw_device *aw_dev,
710695
if (!ret)
711696
aw_dev->prof_info.prof_name_list = profile_name;
712697

713-
exit:
714-
devm_kfree(aw_dev->dev, all_prof_info);
715698
return ret;
716699
}
717700

0 commit comments

Comments
 (0)