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: pcm_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-5-tiwai@suse.de

+10 -23
+10 -23
sound/core/oss/pcm_oss.c
··· 377 377 snd_pcm_hw_param_t var, unsigned int best, 378 378 int *dir) 379 379 { 380 - struct snd_pcm_hw_params *save = NULL; 380 + struct snd_pcm_hw_params *save __free(kfree) = NULL; 381 381 int v; 382 382 unsigned int saved_min; 383 383 int last = 0; ··· 404 404 saved_min = min; 405 405 min = snd_pcm_hw_param_min(pcm, params, var, min, &mindir); 406 406 if (min >= 0) { 407 - struct snd_pcm_hw_params *params1; 407 + struct snd_pcm_hw_params *params1 __free(kfree) = NULL; 408 408 if (max < 0) 409 409 goto _end; 410 410 if ((unsigned int)min == saved_min && mindir == valdir) 411 411 goto _end; 412 412 params1 = kmalloc(sizeof(*params1), GFP_KERNEL); 413 - if (params1 == NULL) { 414 - kfree(save); 413 + if (params1 == NULL) 415 414 return -ENOMEM; 416 - } 417 415 *params1 = *save; 418 416 max = snd_pcm_hw_param_max(pcm, params1, var, max, &maxdir); 419 - if (max < 0) { 420 - kfree(params1); 417 + if (max < 0) 421 418 goto _end; 422 - } 423 419 if (boundary_nearer(max, maxdir, best, valdir, min, mindir)) { 424 420 *params = *params1; 425 421 last = 1; 426 422 } 427 - kfree(params1); 428 423 } else { 429 424 *params = *save; 430 425 max = snd_pcm_hw_param_max(pcm, params, var, max, &maxdir); 431 - if (max < 0) { 432 - kfree(save); 426 + if (max < 0) 433 427 return max; 434 - } 435 428 last = 1; 436 429 } 437 430 _end: 438 - kfree(save); 439 431 if (last) 440 432 v = snd_pcm_hw_param_last(pcm, params, var, dir); 441 433 else ··· 781 789 struct snd_pcm_hw_params *params, unsigned int best_rate) 782 790 { 783 791 const struct snd_interval *it; 784 - struct snd_pcm_hw_params *save; 792 + struct snd_pcm_hw_params *save __free(kfree) = NULL; 785 793 unsigned int rate, prev; 786 794 787 795 save = kmalloc(sizeof(*save), GFP_KERNEL); ··· 800 808 ret = snd_pcm_hw_param_set(substream, params, 801 809 SNDRV_PCM_HW_PARAM_RATE, 802 810 rate, 0); 803 - if (ret == (int)rate) { 804 - kfree(save); 811 + if (ret == (int)rate) 805 812 return rate; 806 - } 807 813 *params = *save; 808 814 } 809 815 prev = rate; ··· 811 821 } 812 822 813 823 /* not found, use the nearest rate */ 814 - kfree(save); 815 824 return snd_pcm_hw_param_near(substream, params, SNDRV_PCM_HW_PARAM_RATE, best_rate, NULL); 816 825 } 817 826 ··· 1836 1847 struct snd_pcm_substream *substream; 1837 1848 int err; 1838 1849 int direct; 1839 - struct snd_pcm_hw_params *params; 1850 + struct snd_pcm_hw_params *params __free(kfree) = NULL; 1840 1851 unsigned int formats = 0; 1841 1852 const struct snd_mask *format_mask; 1842 1853 int fmt; ··· 1862 1873 _snd_pcm_hw_params_any(params); 1863 1874 err = snd_pcm_hw_refine(substream, params); 1864 1875 if (err < 0) 1865 - goto error; 1876 + return err; 1866 1877 format_mask = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT); 1867 1878 for (fmt = 0; fmt < 32; ++fmt) { 1868 1879 if (snd_mask_test(format_mask, fmt)) { ··· 1872 1883 } 1873 1884 } 1874 1885 1875 - error: 1876 - kfree(params); 1877 - return err < 0 ? err : formats; 1886 + return formats; 1878 1887 } 1879 1888 1880 1889 static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int format)