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

soundwire: intel: simplify with cleanup.h

Allocate the memory with scoped/cleanup.h to reduce error handling and
make the code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240703-soundwire-cleanup-h-v1-5-24fa0dbb948f@linaro.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Vinod Koul
e4fcf153 ba874a8c

+4 -7
+4 -7
drivers/soundwire/intel.c
··· 6 6 */ 7 7 8 8 #include <linux/acpi.h> 9 + #include <linux/cleanup.h> 9 10 #include <linux/debugfs.h> 10 11 #include <linux/delay.h> 11 12 #include <linux/io.h> ··· 74 73 struct sdw_intel *sdw = s_file->private; 75 74 void __iomem *s = sdw->link_res->shim; 76 75 void __iomem *a = sdw->link_res->alh; 77 - char *buf; 78 76 ssize_t ret; 79 77 int i, j; 80 78 unsigned int links, reg; 81 79 82 - buf = kzalloc(RD_BUF, GFP_KERNEL); 80 + char *buf __free(kfree) = kzalloc(RD_BUF, GFP_KERNEL); 83 81 if (!buf) 84 82 return -ENOMEM; 85 83 ··· 129 129 ret += intel_sprintf(a, true, buf, ret, SDW_ALH_STRMZCFG(i)); 130 130 131 131 seq_printf(s_file, "%s", buf); 132 - kfree(buf); 133 132 134 133 return 0; 135 134 } ··· 726 727 struct sdw_cdns_dai_runtime *dai_runtime; 727 728 struct sdw_cdns_pdi *pdi; 728 729 struct sdw_stream_config sconfig; 729 - struct sdw_port_config *pconfig; 730 730 int ch, dir; 731 731 int ret; 732 732 ··· 769 771 sconfig.bps = snd_pcm_format_width(params_format(params)); 770 772 771 773 /* Port configuration */ 772 - pconfig = kzalloc(sizeof(*pconfig), GFP_KERNEL); 774 + struct sdw_port_config *pconfig __free(kfree) = kzalloc(sizeof(*pconfig), 775 + GFP_KERNEL); 773 776 if (!pconfig) 774 777 return -ENOMEM; 775 778 ··· 781 782 pconfig, 1, dai_runtime->stream); 782 783 if (ret) 783 784 dev_err(cdns->dev, "add master to stream failed:%d\n", ret); 784 - 785 - kfree(pconfig); 786 785 787 786 return ret; 788 787 }