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.

ALSA: mixer_oss: ump: Use automatic cleanup of kfree()

There are common patterns where a temporary buffer is allocated and
freed at the exit, and those can be simplified with the recent cleanup
mechanism via __free(kfree).

No functional changes, only code refactoring.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20240223084241.3361-4-tiwai@suse.de

+18 -41
+18 -41
sound/core/oss/mixer_oss.c
··· 532 532 unsigned int numid, 533 533 int *left, int *right) 534 534 { 535 - struct snd_ctl_elem_info *uinfo; 536 - struct snd_ctl_elem_value *uctl; 535 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 536 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 537 537 struct snd_kcontrol *kctl; 538 538 struct snd_card *card = fmixer->card; 539 539 ··· 561 561 *right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]); 562 562 __unalloc: 563 563 up_read(&card->controls_rwsem); 564 - kfree(uctl); 565 - kfree(uinfo); 566 564 } 567 565 568 566 static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file *fmixer, ··· 569 571 int *left, int *right, 570 572 int route) 571 573 { 572 - struct snd_ctl_elem_info *uinfo; 573 - struct snd_ctl_elem_value *uctl; 574 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 575 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 574 576 struct snd_kcontrol *kctl; 575 577 struct snd_card *card = fmixer->card; 576 578 ··· 599 601 *right = 0; 600 602 __unalloc: 601 603 up_read(&card->controls_rwsem); 602 - kfree(uctl); 603 - kfree(uinfo); 604 604 } 605 605 606 606 static int snd_mixer_oss_get_volume1(struct snd_mixer_oss_file *fmixer, ··· 632 636 unsigned int numid, 633 637 int left, int right) 634 638 { 635 - struct snd_ctl_elem_info *uinfo; 636 - struct snd_ctl_elem_value *uctl; 639 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 640 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 637 641 struct snd_kcontrol *kctl; 638 642 struct snd_card *card = fmixer->card; 639 643 int res; ··· 665 669 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); 666 670 __unalloc: 667 671 up_read(&card->controls_rwsem); 668 - kfree(uctl); 669 - kfree(uinfo); 670 672 } 671 673 672 674 static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file *fmixer, ··· 673 679 int left, int right, 674 680 int route) 675 681 { 676 - struct snd_ctl_elem_info *uinfo; 677 - struct snd_ctl_elem_value *uctl; 682 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 683 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 678 684 struct snd_kcontrol *kctl; 679 685 struct snd_card *card = fmixer->card; 680 686 int res; ··· 710 716 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); 711 717 __unalloc: 712 718 up_read(&card->controls_rwsem); 713 - kfree(uctl); 714 - kfree(uinfo); 715 719 } 716 720 717 721 static int snd_mixer_oss_put_volume1(struct snd_mixer_oss_file *fmixer, ··· 814 822 struct snd_kcontrol *kctl; 815 823 struct snd_mixer_oss_slot *pslot; 816 824 struct slot *slot; 817 - struct snd_ctl_elem_info *uinfo; 818 - struct snd_ctl_elem_value *uctl; 825 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 826 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 819 827 int err, idx; 820 828 821 829 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); 822 830 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 823 - if (uinfo == NULL || uctl == NULL) { 824 - err = -ENOMEM; 825 - goto __free_only; 826 - } 831 + if (uinfo == NULL || uctl == NULL) 832 + return -ENOMEM; 827 833 down_read(&card->controls_rwsem); 828 834 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); 829 835 if (! kctl) { ··· 851 861 err = 0; 852 862 __unlock: 853 863 up_read(&card->controls_rwsem); 854 - __free_only: 855 - kfree(uctl); 856 - kfree(uinfo); 857 864 return err; 858 865 } 859 866 ··· 861 874 struct snd_kcontrol *kctl; 862 875 struct snd_mixer_oss_slot *pslot; 863 876 struct slot *slot = NULL; 864 - struct snd_ctl_elem_info *uinfo; 865 - struct snd_ctl_elem_value *uctl; 877 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 878 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 866 879 int err; 867 880 unsigned int idx; 868 881 869 882 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); 870 883 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); 871 - if (uinfo == NULL || uctl == NULL) { 872 - err = -ENOMEM; 873 - goto __free_only; 874 - } 884 + if (uinfo == NULL || uctl == NULL) 885 + return -ENOMEM; 875 886 down_read(&card->controls_rwsem); 876 887 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); 877 888 if (! kctl) { ··· 902 917 err = 0; 903 918 __unlock: 904 919 up_read(&card->controls_rwsem); 905 - __free_only: 906 - kfree(uctl); 907 - kfree(uinfo); 908 920 return err; 909 921 } 910 922 ··· 913 931 914 932 static int snd_mixer_oss_build_test(struct snd_mixer_oss *mixer, struct slot *slot, const char *name, int index, int item) 915 933 { 916 - struct snd_ctl_elem_info *info; 934 + struct snd_ctl_elem_info *info __free(kfree) = NULL; 917 935 struct snd_kcontrol *kcontrol; 918 936 struct snd_card *card = mixer->card; 919 937 int err; ··· 932 950 err = kcontrol->info(kcontrol, info); 933 951 if (err < 0) { 934 952 up_read(&card->controls_rwsem); 935 - kfree(info); 936 953 return err; 937 954 } 938 955 slot->numid[item] = kcontrol->id.numid; ··· 939 958 if (info->count > slot->channels) 940 959 slot->channels = info->count; 941 960 slot->present |= 1 << item; 942 - kfree(info); 943 961 return 0; 944 962 } 945 963 ··· 1053 1073 if (!ptr->index) 1054 1074 kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0); 1055 1075 if (kctl) { 1056 - struct snd_ctl_elem_info *uinfo; 1076 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 1057 1077 1058 1078 uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL); 1059 1079 if (! uinfo) { ··· 1063 1083 1064 1084 if (kctl->info(kctl, uinfo)) { 1065 1085 up_read(&mixer->card->controls_rwsem); 1066 - kfree(uinfo); 1067 1086 return 0; 1068 1087 } 1069 1088 strcpy(str, ptr->name); ··· 1078 1099 uinfo->value.enumerated.item = slot.capture_item; 1079 1100 if (kctl->info(kctl, uinfo)) { 1080 1101 up_read(&mixer->card->controls_rwsem); 1081 - kfree(uinfo); 1082 1102 return 0; 1083 1103 } 1084 1104 if (!strcmp(uinfo->value.enumerated.name, str)) { ··· 1086 1108 } 1087 1109 } 1088 1110 } 1089 - kfree(uinfo); 1090 1111 } 1091 1112 up_read(&mixer->card->controls_rwsem); 1092 1113 if (slot.present != 0) {