Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <krzysztof.kozlowski@linaro.org>
Link: https://patch.msgid.link/20240701171917.596173-1-krzysztof.kozlowski@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Mark Brown
d0f4ce8a e52a73e6

+17 -34
+17 -34
sound/soc/codecs/aw88395/aw88395_lib.c
··· 7 7 // Author: Bruce zhao <zhaolei@awinic.com> 8 8 // 9 9 10 + #include <linux/cleanup.h> 10 11 #include <linux/crc8.h> 11 12 #include <linux/i2c.h> 12 13 #include "aw88395_lib.h" ··· 362 361 static int aw_dev_prof_parse_multi_bin(struct aw_device *aw_dev, unsigned char *data, 363 362 unsigned int data_len, struct aw_prof_desc *prof_desc) 364 363 { 365 - struct aw_bin *aw_bin; 366 364 int ret; 367 365 int i; 368 366 369 - aw_bin = devm_kzalloc(aw_dev->dev, data_len + sizeof(struct aw_bin), GFP_KERNEL); 367 + struct aw_bin *aw_bin __free(kfree) = kzalloc(data_len + sizeof(struct aw_bin), 368 + GFP_KERNEL); 370 369 if (!aw_bin) 371 370 return -ENOMEM; 372 371 ··· 376 375 ret = aw_parsing_bin_file(aw_dev, aw_bin); 377 376 if (ret < 0) { 378 377 dev_err(aw_dev->dev, "parse bin failed"); 379 - goto parse_bin_failed; 378 + return ret; 380 379 } 381 380 382 381 for (i = 0; i < aw_bin->all_bin_parse_num; i++) { ··· 388 387 data + aw_bin->header_info[i].valid_data_addr; 389 388 break; 390 389 case DATA_TYPE_DSP_REG: 391 - if (aw_bin->header_info[i].valid_data_len & 0x01) { 392 - ret = -EINVAL; 393 - goto parse_bin_failed; 394 - } 390 + if (aw_bin->header_info[i].valid_data_len & 0x01) 391 + return -EINVAL; 395 392 396 393 swab16_array((u16 *)(data + aw_bin->header_info[i].valid_data_addr), 397 394 aw_bin->header_info[i].valid_data_len >> 1); ··· 401 402 break; 402 403 case DATA_TYPE_DSP_FW: 403 404 case DATA_TYPE_SOC_APP: 404 - if (aw_bin->header_info[i].valid_data_len & 0x01) { 405 - ret = -EINVAL; 406 - goto parse_bin_failed; 407 - } 405 + if (aw_bin->header_info[i].valid_data_len & 0x01) 406 + return -EINVAL; 408 407 409 408 swab16_array((u16 *)(data + aw_bin->header_info[i].valid_data_addr), 410 409 aw_bin->header_info[i].valid_data_len >> 1); ··· 419 422 } 420 423 } 421 424 prof_desc->prof_st = AW88395_PROFILE_OK; 422 - ret = 0; 423 425 424 - parse_bin_failed: 425 - devm_kfree(aw_dev->dev, aw_bin); 426 - return ret; 426 + return 0; 427 427 } 428 428 429 429 static int aw_dev_parse_reg_bin_with_hdr(struct aw_device *aw_dev, 430 430 uint8_t *data, uint32_t data_len, struct aw_prof_desc *prof_desc) 431 431 { 432 - struct aw_bin *aw_bin; 433 432 int ret; 434 433 435 - aw_bin = devm_kzalloc(aw_dev->dev, data_len + sizeof(*aw_bin), GFP_KERNEL); 434 + struct aw_bin *aw_bin __free(kfree) = kzalloc(data_len + sizeof(*aw_bin), 435 + GFP_KERNEL); 436 436 if (!aw_bin) 437 437 return -ENOMEM; 438 438 ··· 439 445 ret = aw_parsing_bin_file(aw_dev, aw_bin); 440 446 if (ret < 0) { 441 447 dev_err(aw_dev->dev, "parse bin failed"); 442 - goto parse_bin_failed; 448 + return ret; 443 449 } 444 450 445 451 if ((aw_bin->all_bin_parse_num != 1) || 446 452 (aw_bin->header_info[0].bin_data_type != DATA_TYPE_REGISTER)) { 447 453 dev_err(aw_dev->dev, "bin num or type error"); 448 - ret = -EINVAL; 449 - goto parse_bin_failed; 454 + return -EINVAL; 450 455 } 451 456 452 457 prof_desc->sec_desc[AW88395_DATA_TYPE_REG].data = ··· 454 461 aw_bin->header_info[0].valid_data_len; 455 462 prof_desc->prof_st = AW88395_PROFILE_OK; 456 463 457 - devm_kfree(aw_dev->dev, aw_bin); 458 - aw_bin = NULL; 459 - 460 464 return 0; 461 - 462 - parse_bin_failed: 463 - devm_kfree(aw_dev->dev, aw_bin); 464 - aw_bin = NULL; 465 - return ret; 466 465 } 467 466 468 467 static int aw_dev_parse_data_by_sec_type(struct aw_device *aw_dev, struct aw_cfg_hdr *cfg_hdr, ··· 663 678 static int aw_dev_load_cfg_by_hdr(struct aw_device *aw_dev, 664 679 struct aw_cfg_hdr *prof_hdr) 665 680 { 666 - struct aw_all_prof_info *all_prof_info; 667 681 int ret; 668 682 669 - all_prof_info = devm_kzalloc(aw_dev->dev, sizeof(struct aw_all_prof_info), GFP_KERNEL); 683 + struct aw_all_prof_info *all_prof_info __free(kfree) = kzalloc(sizeof(*all_prof_info), 684 + GFP_KERNEL); 670 685 if (!all_prof_info) 671 686 return -ENOMEM; 672 687 673 688 ret = aw_dev_parse_dev_type(aw_dev, prof_hdr, all_prof_info); 674 689 if (ret < 0) { 675 - goto exit; 690 + return ret; 676 691 } else if (ret == AW88395_DEV_TYPE_NONE) { 677 692 dev_dbg(aw_dev->dev, "get dev type num is 0, parse default dev"); 678 693 ret = aw_dev_parse_dev_default_type(aw_dev, prof_hdr, all_prof_info); 679 694 if (ret < 0) 680 - goto exit; 695 + return ret; 681 696 } 682 697 683 698 switch (aw_dev->prof_data_type) { ··· 695 710 if (!ret) 696 711 aw_dev->prof_info.prof_name_list = profile_name; 697 712 698 - exit: 699 - devm_kfree(aw_dev->dev, all_prof_info); 700 713 return ret; 701 714 } 702 715