Message ID | 20231227060322.3556052-1-alexious@zju.edu.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-11844-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1263986dyb; Tue, 26 Dec 2023 22:05:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQw7fVyuL3VIkJTS52aWAwdPiqQiVxkIH1bG6AklErEzsMev6XxRVnvtA5QtT5YSHxytJh X-Received: by 2002:a05:6214:21ee:b0:67f:66fa:e1ca with SMTP id p14-20020a05621421ee00b0067f66fae1camr10860789qvj.110.1703657124608; Tue, 26 Dec 2023 22:05:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703657124; cv=none; d=google.com; s=arc-20160816; b=LUcRo5KPOXNKF5kfz4vgORkf9YHmGFVfrOc+z0CwebDriuYdka8H2yFTA4sNZF2BDy veRC9DXo8OQ5dWYAi9PK4BCq9/5KXLBhM5hc/pMCaZhSkUeU86yNcuKJQapewlD2BxAM HKX06uGoktN5wTGCgKKAP5i6smMKlGMuv09iNLKmbpNJxE9yPyH5KCL4oXZgyWqQ3bRp qtW15ekHPV+PJR/9U0KV4tOL4+D4Gr7NV6UzcPFwTze5NfEwl8Fm28xL3Pv1w3ZwOf+I HBgsJEilKp4onKcmhfFmI0NHruFXb7bjAJYmffmrcAgF/HnKptPuaOMXWlHEQ3YrFwL0 F4WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=Op6qMDLxqx6O9XlNfHxIPQf/idhgQEnfJV45FcLLqZ4=; fh=BtX23WJHG1z80J0llbTQmgTdloy8WDV4wo8/UpwlUMk=; b=YxQIUByRGiFJKB7l8oPrQLCvbdrri16r9GODnl6qeOhK8xJOYw1IJxh3flOQP147Ga b92jETbxrBY/pRH1lv/kxap8XwR95EliDt3xzGAx/4RK2lwSbWoHNwkAlQUymJesUhwC IKvaF1ZBHQh6HeyXYaH8JqjlW/07S7bEDgwMoUflsKj90U9nwe/emWXHIppeU2ch4wzZ 02gh4Ifycf/4RzS43QV7M42wRHGh3IkWz9sVZVdyv0lnmEyOLho7sN6p8PWuQt/1y4S+ cCXhcgB6bT+cSncudsUsahqIDqouT8zQXxZmzvwRqnv3S5ExnJFj2hhkCr6tAIrTTCgI jzxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11844-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11844-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id o17-20020a0ce411000000b0067f92e3d944si11722231qvl.398.2023.12.26.22.05.24 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 22:05:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11844-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11844-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11844-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 661AB1C20DB2 for <ouuuleilei@gmail.com>; Wed, 27 Dec 2023 06:05:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C0D55687; Wed, 27 Dec 2023 06:05:03 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [207.46.229.174]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5DE3D5220; Wed, 27 Dec 2023 06:04:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from luzhipeng.223.5.5.5 (unknown [115.200.231.230]) by mail-app3 (Coremail) with SMTP id cC_KCgAHAhmCvotl__uKAQ--.53033S2; Wed, 27 Dec 2023 14:04:51 +0800 (CST) From: Zhipeng Lu <alexious@zju.edu.cn> To: alexious@zju.edu.cn Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] ALSA: hdsp: fix some memleaks in snd_hdsp_hwdep_ioctl Date: Wed, 27 Dec 2023 14:03:20 +0800 Message-Id: <20231227060322.3556052-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cC_KCgAHAhmCvotl__uKAQ--.53033S2 X-Coremail-Antispam: 1UD129KBjvJXoW7ArW8ZFyDZr1kWrWxJF4UXFb_yoW8CF4rpF WfW3yjkr48JrWFkanrJw1DWFn0kFn7tayrWrWrC34Iyr15Awn0vF9Y9rWv9FyYgr4rWw4x Kw1Fva45Cr1UtF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUka14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE14v_GF1l 42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJV WUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAK I48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r 4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY 6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x0JU24E_UUUUU= X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786413972914237915 X-GMAIL-MSGID: 1786413972914237915 |
Series |
[v2] ALSA: hdsp: fix some memleaks in snd_hdsp_hwdep_ioctl
|
|
Commit Message
Zhipeng Lu
Dec. 27, 2023, 6:03 a.m. UTC
When snd_hdsp_load_firmware_from_cache and snd_hdsp_enable_io fails,
the hdsp->fw_uploaded needs to be free.Or there could be memleaks in
snd_hdsp_hwdep_ioctl.
Fixes: 90caaef6a1ce ("ALSA: hdsp: improve firmware caching")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
---
Changelog:
v2: remove label 'err' which is unused.
---
sound/pci/rme9652/hdsp.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
Comments
On Wed, 27 Dec 2023 07:03:20 +0100, Zhipeng Lu wrote: > > When snd_hdsp_load_firmware_from_cache and snd_hdsp_enable_io fails, > the hdsp->fw_uploaded needs to be free.Or there could be memleaks in > snd_hdsp_hwdep_ioctl. > > Fixes: 90caaef6a1ce ("ALSA: hdsp: improve firmware caching") > Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn> Thanks for the patch, but the patch description is misleading. The allocated object isn't really "leaked"; it's released at the removal of the driver. We may apply some optimization like you did, but then it should have a different description. thanks, Takashi
Hi Zhipeng, kernel test robot noticed the following build warnings: https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Zhipeng-Lu/ALSA-hdsp-fix-some-memleaks-in-snd_hdsp_hwdep_ioctl/20231227-140703 base: https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next patch link: https://lore.kernel.org/r/20231227060322.3556052-1-alexious%40zju.edu.cn patch subject: [PATCH] [v2] ALSA: hdsp: fix some memleaks in snd_hdsp_hwdep_ioctl config: i386-randconfig-141-20240104 (https://download.01.org/0day-ci/archive/20240105/202401051031.8odmcqKi-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Reported-by: Dan Carpenter <dan.carpenter@linaro.org> | Closes: https://lore.kernel.org/r/202401051031.8odmcqKi-lkp@intel.com/ New smatch warnings: sound/pci/rme9652/hdsp.c:4918 snd_hdsp_hwdep_ioctl() error: uninitialized symbol 'err'. Old smatch warnings: sound/pci/rme9652/hdsp.c:3405 snd_hdsp_proc_read() warn: argument 5 to %lx specifier is cast from pointer sound/pci/rme9652/hdsp.c:5219 hdsp_request_fw_loader() warn: 'fw' from request_firmware() not released on lines: 5197,5202,5208,5216. vim +/err +4918 sound/pci/rme9652/hdsp.c 55e957d8328ef1 Takashi Iwai 2005-11-17 4728 static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4729 { 9fe856e47e1751 Joe Perches 2010-09-04 4730 struct hdsp *hdsp = hw->private_data; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4731 void __user *argp = (void __user *)arg; 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4732 int err; err is first declared here ^1da177e4c3f41 Linus Torvalds 2005-04-16 4733 ^1da177e4c3f41 Linus Torvalds 2005-04-16 4734 switch (cmd) { ^1da177e4c3f41 Linus Torvalds 2005-04-16 4735 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: { 55e957d8328ef1 Takashi Iwai 2005-11-17 4736 struct hdsp_peak_rms __user *peak_rms = (struct hdsp_peak_rms __user *)arg; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4737 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4738 err = hdsp_check_for_iobox(hdsp); 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4739 if (err < 0) 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4740 return err; 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4741 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4742 err = hdsp_check_for_firmware(hdsp, 1); 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4743 if (err < 0) 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4744 return err; 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4745 ^1da177e4c3f41 Linus Torvalds 2005-04-16 4746 if (!(hdsp->state & HDSP_FirmwareLoaded)) { a54ba0fe9fae3c Takashi Iwai 2014-02-26 4747 dev_err(hdsp->card->dev, a54ba0fe9fae3c Takashi Iwai 2014-02-26 4748 "firmware needs to be uploaded to the card.\n"); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4749 return -EINVAL; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4750 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4751 ^1da177e4c3f41 Linus Torvalds 2005-04-16 4752 switch (hdsp->io_type) { ^1da177e4c3f41 Linus Torvalds 2005-04-16 4753 case H9652: ^1da177e4c3f41 Linus Torvalds 2005-04-16 4754 return hdsp_9652_get_peak(hdsp, peak_rms); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4755 case H9632: ^1da177e4c3f41 Linus Torvalds 2005-04-16 4756 return hdsp_9632_get_peak(hdsp, peak_rms); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4757 default: ^1da177e4c3f41 Linus Torvalds 2005-04-16 4758 return hdsp_get_peak(hdsp, peak_rms); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4759 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4760 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4761 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: { 55e957d8328ef1 Takashi Iwai 2005-11-17 4762 struct hdsp_config_info info; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4763 unsigned long flags; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4764 int i; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4765 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4766 err = hdsp_check_for_iobox(hdsp); 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4767 if (err < 0) 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4768 return err; 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4769 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4770 err = hdsp_check_for_firmware(hdsp, 1); 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4771 if (err < 0) 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4772 return err; 3ae7e2e22900b9 Tim Blechmann 2008-11-08 4773 e68d3b316ab7b0 Dan Rosenberg 2010-09-25 4774 memset(&info, 0, sizeof(info)); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4775 spin_lock_irqsave(&hdsp->lock, flags); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4776 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4777 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp); b0b9811956db48 Takashi Iwai 2005-10-20 4778 if (hdsp->io_type != H9632) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4779 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4780 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp); 28b26e15533e60 Florian Faber 2010-12-01 4781 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632) ? 3 : 1); ++i) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4782 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4783 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp); 4833c673dee69a Adrian Knoth 2013-01-15 4784 info.spdif_out = (unsigned char)hdsp_toggle_setting(hdsp, 4833c673dee69a Adrian Knoth 2013-01-15 4785 HDSP_SPDIFOpticalOut); 4833c673dee69a Adrian Knoth 2013-01-15 4786 info.spdif_professional = (unsigned char) 4833c673dee69a Adrian Knoth 2013-01-15 4787 hdsp_toggle_setting(hdsp, HDSP_SPDIFProfessional); 4833c673dee69a Adrian Knoth 2013-01-15 4788 info.spdif_emphasis = (unsigned char) 4833c673dee69a Adrian Knoth 2013-01-15 4789 hdsp_toggle_setting(hdsp, HDSP_SPDIFEmphasis); 4833c673dee69a Adrian Knoth 2013-01-15 4790 info.spdif_nonaudio = (unsigned char) 4833c673dee69a Adrian Knoth 2013-01-15 4791 hdsp_toggle_setting(hdsp, HDSP_SPDIFNonAudio); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4792 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4793 info.system_sample_rate = hdsp->system_sample_rate; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4794 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4795 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4796 info.clock_source = (unsigned char)hdsp_clock_source(hdsp); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4797 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp); 4833c673dee69a Adrian Knoth 2013-01-15 4798 info.line_out = (unsigned char) 4833c673dee69a Adrian Knoth 2013-01-15 4799 hdsp_toggle_setting(hdsp, HDSP_LineOut); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4800 if (hdsp->io_type == H9632) { ^1da177e4c3f41 Linus Torvalds 2005-04-16 4801 info.da_gain = (unsigned char)hdsp_da_gain(hdsp); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4802 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4803 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp); 4833c673dee69a Adrian Knoth 2013-01-15 4804 info.xlr_breakout_cable = 4833c673dee69a Adrian Knoth 2013-01-15 4805 (unsigned char)hdsp_toggle_setting(hdsp, 4833c673dee69a Adrian Knoth 2013-01-15 4806 HDSP_XLRBreakoutCable); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4807 28b26e15533e60 Florian Faber 2010-12-01 4808 } else if (hdsp->io_type == RPM) { 28b26e15533e60 Florian Faber 2010-12-01 4809 info.da_gain = (unsigned char) hdsp_rpm_input12(hdsp); 28b26e15533e60 Florian Faber 2010-12-01 4810 info.ad_gain = (unsigned char) hdsp_rpm_input34(hdsp); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4811 } b0b9811956db48 Takashi Iwai 2005-10-20 4812 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) 4833c673dee69a Adrian Knoth 2013-01-15 4813 info.analog_extension_board = 4833c673dee69a Adrian Knoth 2013-01-15 4814 (unsigned char)hdsp_toggle_setting(hdsp, 4833c673dee69a Adrian Knoth 2013-01-15 4815 HDSP_AnalogExtensionBoard); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4816 spin_unlock_irqrestore(&hdsp->lock, flags); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4817 if (copy_to_user(argp, &info, sizeof(info))) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4818 return -EFAULT; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4819 break; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4820 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4821 case SNDRV_HDSP_IOCTL_GET_9632_AEB: { 55e957d8328ef1 Takashi Iwai 2005-11-17 4822 struct hdsp_9632_aeb h9632_aeb; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4823 ^1da177e4c3f41 Linus Torvalds 2005-04-16 4824 if (hdsp->io_type != H9632) return -EINVAL; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4825 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4826 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4827 if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb))) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4828 return -EFAULT; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4829 break; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4830 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4831 case SNDRV_HDSP_IOCTL_GET_VERSION: { 55e957d8328ef1 Takashi Iwai 2005-11-17 4832 struct hdsp_version hdsp_version; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4833 int err; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4834 ^1da177e4c3f41 Linus Torvalds 2005-04-16 4835 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4836 if (hdsp->io_type == Undefined) { 66c8f75919dd85 Takashi Iwai 2021-06-08 4837 err = hdsp_get_iobox_version(hdsp); 66c8f75919dd85 Takashi Iwai 2021-06-08 4838 if (err < 0) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4839 return err; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4840 } d14df339c72b6e Dan Carpenter 2013-10-16 4841 memset(&hdsp_version, 0, sizeof(hdsp_version)); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4842 hdsp_version.io_type = hdsp->io_type; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4843 hdsp_version.firmware_rev = hdsp->firmware_rev; 0f7c956533680d Dan Carpenter 2021-06-22 4844 if (copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4845 return -EFAULT; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4846 break; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4847 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4848 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: { 112e3f5ac505ea Takashi Iwai 2020-02-02 4849 struct hdsp_firmware firmware; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4850 u32 __user *firmware_data; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4851 int err; This err shadows the earlier declaration ^1da177e4c3f41 Linus Torvalds 2005-04-16 4852 ^1da177e4c3f41 Linus Torvalds 2005-04-16 4853 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4854 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */ ^1da177e4c3f41 Linus Torvalds 2005-04-16 4855 if (hdsp->io_type == Undefined) return -EINVAL; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4856 ^1da177e4c3f41 Linus Torvalds 2005-04-16 4857 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded)) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4858 return -EBUSY; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4859 a54ba0fe9fae3c Takashi Iwai 2014-02-26 4860 dev_info(hdsp->card->dev, a54ba0fe9fae3c Takashi Iwai 2014-02-26 4861 "initializing firmware upload\n"); 112e3f5ac505ea Takashi Iwai 2020-02-02 4862 if (copy_from_user(&firmware, argp, sizeof(firmware))) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4863 return -EFAULT; 112e3f5ac505ea Takashi Iwai 2020-02-02 4864 firmware_data = (u32 __user *)firmware.firmware_data; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4865 b0b9811956db48 Takashi Iwai 2005-10-20 4866 if (hdsp_check_for_iobox (hdsp)) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4867 return -EIO; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4868 90caaef6a1ce2e Takashi Iwai 2012-11-22 4869 if (!hdsp->fw_uploaded) { 90caaef6a1ce2e Takashi Iwai 2012-11-22 4870 hdsp->fw_uploaded = vmalloc(HDSP_FIRMWARE_SIZE); 90caaef6a1ce2e Takashi Iwai 2012-11-22 4871 if (!hdsp->fw_uploaded) 90caaef6a1ce2e Takashi Iwai 2012-11-22 4872 return -ENOMEM; 90caaef6a1ce2e Takashi Iwai 2012-11-22 4873 } 90caaef6a1ce2e Takashi Iwai 2012-11-22 4874 90caaef6a1ce2e Takashi Iwai 2012-11-22 4875 if (copy_from_user(hdsp->fw_uploaded, firmware_data, 90caaef6a1ce2e Takashi Iwai 2012-11-22 4876 HDSP_FIRMWARE_SIZE)) { b0d4acf304f079 Zhipeng Lu 2023-12-27 4877 err = -EFAULT; b0d4acf304f079 Zhipeng Lu 2023-12-27 4878 goto free_fw_uploaded; 90caaef6a1ce2e Takashi Iwai 2012-11-22 4879 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4880 ^1da177e4c3f41 Linus Torvalds 2005-04-16 4881 hdsp->state |= HDSP_FirmwareCached; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4882 66c8f75919dd85 Takashi Iwai 2021-06-08 4883 err = snd_hdsp_load_firmware_from_cache(hdsp); 66c8f75919dd85 Takashi Iwai 2021-06-08 4884 if (err < 0) b0d4acf304f079 Zhipeng Lu 2023-12-27 4885 goto free_fw_uploaded; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4886 ^1da177e4c3f41 Linus Torvalds 2005-04-16 4887 if (!(hdsp->state & HDSP_InitializationComplete)) { 66c8f75919dd85 Takashi Iwai 2021-06-08 4888 err = snd_hdsp_enable_io(hdsp); 66c8f75919dd85 Takashi Iwai 2021-06-08 4889 if (err < 0) b0d4acf304f079 Zhipeng Lu 2023-12-27 4890 goto free_fw_uploaded; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4891 ^1da177e4c3f41 Linus Torvalds 2005-04-16 4892 snd_hdsp_initialize_channels(hdsp); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4893 snd_hdsp_initialize_midi_flush(hdsp); ^1da177e4c3f41 Linus Torvalds 2005-04-16 4894 66c8f75919dd85 Takashi Iwai 2021-06-08 4895 err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp); 66c8f75919dd85 Takashi Iwai 2021-06-08 4896 if (err < 0) { a54ba0fe9fae3c Takashi Iwai 2014-02-26 4897 dev_err(hdsp->card->dev, a54ba0fe9fae3c Takashi Iwai 2014-02-26 4898 "error creating alsa devices\n"); b0d4acf304f079 Zhipeng Lu 2023-12-27 4899 goto free_fw_uploaded; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4900 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4901 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4902 break; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4903 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4904 case SNDRV_HDSP_IOCTL_GET_MIXER: { 55e957d8328ef1 Takashi Iwai 2005-11-17 4905 struct hdsp_mixer __user *mixer = (struct hdsp_mixer __user *)argp; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4906 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE)) ^1da177e4c3f41 Linus Torvalds 2005-04-16 4907 return -EFAULT; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4908 break; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4909 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4910 default: ^1da177e4c3f41 Linus Torvalds 2005-04-16 4911 return -EINVAL; ^1da177e4c3f41 Linus Torvalds 2005-04-16 4912 } ^1da177e4c3f41 Linus Torvalds 2005-04-16 4913 return 0; b0d4acf304f079 Zhipeng Lu 2023-12-27 4914 b0d4acf304f079 Zhipeng Lu 2023-12-27 4915 free_fw_uploaded: b0d4acf304f079 Zhipeng Lu 2023-12-27 4916 vfree(hdsp->fw_uploaded); b0d4acf304f079 Zhipeng Lu 2023-12-27 4917 hdsp->fw_uploaded = NULL; b0d4acf304f079 Zhipeng Lu 2023-12-27 @4918 return err; The first err is uninitialized. ^1da177e4c3f41 Linus Torvalds 2005-04-16 4919 }
> On Wed, 27 Dec 2023 07:03:20 +0100, > Zhipeng Lu wrote: > > > > When snd_hdsp_load_firmware_from_cache and snd_hdsp_enable_io fails, > > the hdsp->fw_uploaded needs to be free.Or there could be memleaks in > > snd_hdsp_hwdep_ioctl. > > > > Fixes: 90caaef6a1ce ("ALSA: hdsp: improve firmware caching") > > Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn> > > Thanks for the patch, but the patch description is misleading. > The allocated object isn't really "leaked"; it's released at the > removal of the driver. It is a little confused to me that I can't find a clear "removal" operation for hdsp->fw_uploaded. Could you please give a more detailed explaination, such as call chain, why hdsp->fw_uploaded is not leaked? Thanks, Zhipeng > We may apply some optimization like you did, but then it should have a > different description. > > thanks, > > Takashi
On Sun, 07 Jan 2024 09:25:12 +0100, alexious@zju.edu.cn wrote: > > > > On Wed, 27 Dec 2023 07:03:20 +0100, > > Zhipeng Lu wrote: > > > > > > When snd_hdsp_load_firmware_from_cache and snd_hdsp_enable_io fails, > > > the hdsp->fw_uploaded needs to be free.Or there could be memleaks in > > > snd_hdsp_hwdep_ioctl. > > > > > > Fixes: 90caaef6a1ce ("ALSA: hdsp: improve firmware caching") > > > Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn> > > > > Thanks for the patch, but the patch description is misleading. > > The allocated object isn't really "leaked"; it's released at the > > removal of the driver. > > It is a little confused to me that I can't find a clear "removal" operation for > hdsp->fw_uploaded. Could you please give a more detailed explaination, > such as call chain, why hdsp->fw_uploaded is not leaked? It's released in snd_hdsp_card_free(). Takashi
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c index e7d1b43471a2..b83b0c484f8e 100644 --- a/sound/pci/rme9652/hdsp.c +++ b/sound/pci/rme9652/hdsp.c @@ -4874,21 +4874,20 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne if (copy_from_user(hdsp->fw_uploaded, firmware_data, HDSP_FIRMWARE_SIZE)) { - vfree(hdsp->fw_uploaded); - hdsp->fw_uploaded = NULL; - return -EFAULT; + err = -EFAULT; + goto free_fw_uploaded; } hdsp->state |= HDSP_FirmwareCached; err = snd_hdsp_load_firmware_from_cache(hdsp); if (err < 0) - return err; + goto free_fw_uploaded; if (!(hdsp->state & HDSP_InitializationComplete)) { err = snd_hdsp_enable_io(hdsp); if (err < 0) - return err; + goto free_fw_uploaded; snd_hdsp_initialize_channels(hdsp); snd_hdsp_initialize_midi_flush(hdsp); @@ -4897,7 +4896,7 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne if (err < 0) { dev_err(hdsp->card->dev, "error creating alsa devices\n"); - return err; + goto free_fw_uploaded; } } break; @@ -4912,6 +4911,11 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne return -EINVAL; } return 0; + +free_fw_uploaded: + vfree(hdsp->fw_uploaded); + hdsp->fw_uploaded = NULL; + return err; } static const struct snd_pcm_ops snd_hdsp_playback_ops = {