Message ID | 20231224082533.3540468-1-alexious@zju.edu.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-10658-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp2037126dyi; Sun, 24 Dec 2023 00:26:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrAPhfOd9ZV2CDeps0A6giJRn6cUGHx/axslWQgfJ6SG5vtrWB4gF9yB0X+n+3OywkDMHo X-Received: by 2002:a50:c191:0:b0:554:afe2:aebe with SMTP id m17-20020a50c191000000b00554afe2aebemr873937edf.78.1703406383845; Sun, 24 Dec 2023 00:26:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703406383; cv=none; d=google.com; s=arc-20160816; b=yjj9HeiKA/y/HT9YPkwALRExUe9pZHBYRb0w2NRFDFj0L3lEJ31jxdNoNKe6SxyuCu nqROHtyr/MM2810KIzoSnlCivvc04rZUFgJKlo4N7OBvn1VyU6EH0BjWbKp0+rB1HsUI hUKr1iMmxdJrLt1ekjNGb6sjwoxevVscRD+xe5rZtFHUrB6/J1p+75YLi6/dvkHs4mEP +ud62iMxAJ5pOYk3iYkhKGcn+si9n0LoRXgeMz9NQfdIVg++GQgN7Twq6eGp5DaBvVxD ut7/5LRdbD4JvNyJ1B4jwJJvRuZh8Q6cY8TWxZAfK393f0I9M+PMFPvHN6MO4ggQ0o4W +fOQ== 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=JUrC0jH9E3QTm4VWe7coBlZRe5BSoolIN8lufTrWZQg=; fh=BtX23WJHG1z80J0llbTQmgTdloy8WDV4wo8/UpwlUMk=; b=kvj4BLUi8CL22CG7hliFIT/MrdIi64u7vJN+nEhK83mz0PBDhzADRDVjH/qqU2gj94 U381EkWQsEcFohaTx5TQqZ5+9iKT0jiQopm4y/YxQmKHVOkkVHABRlVar9G0DfUsu+do bga78aplgr88xMyKiGV5uOJMrqczc7wEtzGrqmi0PK4+MpMfn37ioBIzGJkHgF9tcC2h 94C+3u0tJO7DdWgA1Rq98NtewyITuBgAsPMUbrnTjU6LBHuuonNlz+mUytPX0tezfp5I arL1cbwK58qEFV3hMowv+klx4+bEy4CeIiXWM3Wwjwyg1OqSoBUdvGmj9uqEHDiJQonF T4Kw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10658-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10658-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f3-20020a50d543000000b005533fa17a45si3529612edj.526.2023.12.24.00.26.23 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 00:26:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10658-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10658-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10658-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 75D281F219A7 for <ouuuleilei@gmail.com>; Sun, 24 Dec 2023 08:26:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA66F20E0; Sun, 24 Dec 2023 08:26:09 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net (zg8tmtyylji0my4xnjqumte4.icoremail.net [162.243.164.118]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C100317D4; Sun, 24 Dec 2023 08:26:04 +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 [122.235.137.177]) by mail-app3 (Coremail) with SMTP id cC_KCgCHjBkT64dlc81jAQ--.7486S2; Sun, 24 Dec 2023 16:25:55 +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] ALSA: hdsp: fix some memleaks in snd_hdsp_hwdep_ioctl Date: Sun, 24 Dec 2023 16:25:31 +0800 Message-Id: <20231224082533.3540468-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_KCgCHjBkT64dlc81jAQ--.7486S2 X-Coremail-Antispam: 1UD129KBjvJXoW7ArW8ZFyDZr1kWrWxJF4UXFb_yoW8Cr48pF WfG3yjkrW8JrWFkanrJw1DWrn0kFn7tay5WrWrC34Iyr1YywnYvF9Y9rWv9Fyagr1rWw4x Kw4Fva45Cr1UtF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkv14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK67AK6r43 MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr 0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0E wIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJV W8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF 0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JU38n5UUUUU= X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786151052429533269 X-GMAIL-MSGID: 1786151052429533269 |
Series |
ALSA: hdsp: fix some memleaks in snd_hdsp_hwdep_ioctl
|
|
Commit Message
Zhipeng Lu
Dec. 24, 2023, 8:25 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>
---
sound/pci/rme9652/hdsp.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
Comments
Hi Zhipeng, kernel test robot noticed the following build warnings: [auto build test WARNING on tiwai-sound/for-next] [also build test WARNING on tiwai-sound/for-linus linus/master v6.7-rc7 next-20231222] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in 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/20231225-155210 base: https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next patch link: https://lore.kernel.org/r/20231224082533.3540468-1-alexious%40zju.edu.cn patch subject: [PATCH] ALSA: hdsp: fix some memleaks in snd_hdsp_hwdep_ioctl config: i386-buildonly-randconfig-004-20231225 (https://download.01.org/0day-ci/archive/20231226/202312260629.HwV1r2MX-lkp@intel.com/config) compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231226/202312260629.HwV1r2MX-lkp@intel.com/reproduce) 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> | Closes: https://lore.kernel.org/oe-kbuild-all/202312260629.HwV1r2MX-lkp@intel.com/ All warnings (new ones prefixed by >>): >> sound/pci/rme9652/hdsp.c:4917:1: warning: unused label 'err' [-Wunused-label] err: ^~~~ >> sound/pci/rme9652/hdsp.c:4918:9: warning: variable 'err' is uninitialized when used here [-Wuninitialized] return err; ^~~ sound/pci/rme9652/hdsp.c:4732:9: note: initialize the variable 'err' to silence this warning int err; ^ = 0 2 warnings generated. vim +/err +4917 sound/pci/rme9652/hdsp.c 4727 4728 static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg) 4729 { 4730 struct hdsp *hdsp = hw->private_data; 4731 void __user *argp = (void __user *)arg; 4732 int err; 4733 4734 switch (cmd) { 4735 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: { 4736 struct hdsp_peak_rms __user *peak_rms = (struct hdsp_peak_rms __user *)arg; 4737 4738 err = hdsp_check_for_iobox(hdsp); 4739 if (err < 0) 4740 return err; 4741 4742 err = hdsp_check_for_firmware(hdsp, 1); 4743 if (err < 0) 4744 return err; 4745 4746 if (!(hdsp->state & HDSP_FirmwareLoaded)) { 4747 dev_err(hdsp->card->dev, 4748 "firmware needs to be uploaded to the card.\n"); 4749 return -EINVAL; 4750 } 4751 4752 switch (hdsp->io_type) { 4753 case H9652: 4754 return hdsp_9652_get_peak(hdsp, peak_rms); 4755 case H9632: 4756 return hdsp_9632_get_peak(hdsp, peak_rms); 4757 default: 4758 return hdsp_get_peak(hdsp, peak_rms); 4759 } 4760 } 4761 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: { 4762 struct hdsp_config_info info; 4763 unsigned long flags; 4764 int i; 4765 4766 err = hdsp_check_for_iobox(hdsp); 4767 if (err < 0) 4768 return err; 4769 4770 err = hdsp_check_for_firmware(hdsp, 1); 4771 if (err < 0) 4772 return err; 4773 4774 memset(&info, 0, sizeof(info)); 4775 spin_lock_irqsave(&hdsp->lock, flags); 4776 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp); 4777 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp); 4778 if (hdsp->io_type != H9632) 4779 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp); 4780 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp); 4781 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632) ? 3 : 1); ++i) 4782 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i); 4783 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp); 4784 info.spdif_out = (unsigned char)hdsp_toggle_setting(hdsp, 4785 HDSP_SPDIFOpticalOut); 4786 info.spdif_professional = (unsigned char) 4787 hdsp_toggle_setting(hdsp, HDSP_SPDIFProfessional); 4788 info.spdif_emphasis = (unsigned char) 4789 hdsp_toggle_setting(hdsp, HDSP_SPDIFEmphasis); 4790 info.spdif_nonaudio = (unsigned char) 4791 hdsp_toggle_setting(hdsp, HDSP_SPDIFNonAudio); 4792 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp); 4793 info.system_sample_rate = hdsp->system_sample_rate; 4794 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp); 4795 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp); 4796 info.clock_source = (unsigned char)hdsp_clock_source(hdsp); 4797 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp); 4798 info.line_out = (unsigned char) 4799 hdsp_toggle_setting(hdsp, HDSP_LineOut); 4800 if (hdsp->io_type == H9632) { 4801 info.da_gain = (unsigned char)hdsp_da_gain(hdsp); 4802 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp); 4803 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp); 4804 info.xlr_breakout_cable = 4805 (unsigned char)hdsp_toggle_setting(hdsp, 4806 HDSP_XLRBreakoutCable); 4807 4808 } else if (hdsp->io_type == RPM) { 4809 info.da_gain = (unsigned char) hdsp_rpm_input12(hdsp); 4810 info.ad_gain = (unsigned char) hdsp_rpm_input34(hdsp); 4811 } 4812 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) 4813 info.analog_extension_board = 4814 (unsigned char)hdsp_toggle_setting(hdsp, 4815 HDSP_AnalogExtensionBoard); 4816 spin_unlock_irqrestore(&hdsp->lock, flags); 4817 if (copy_to_user(argp, &info, sizeof(info))) 4818 return -EFAULT; 4819 break; 4820 } 4821 case SNDRV_HDSP_IOCTL_GET_9632_AEB: { 4822 struct hdsp_9632_aeb h9632_aeb; 4823 4824 if (hdsp->io_type != H9632) return -EINVAL; 4825 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS; 4826 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS; 4827 if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb))) 4828 return -EFAULT; 4829 break; 4830 } 4831 case SNDRV_HDSP_IOCTL_GET_VERSION: { 4832 struct hdsp_version hdsp_version; 4833 int err; 4834 4835 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; 4836 if (hdsp->io_type == Undefined) { 4837 err = hdsp_get_iobox_version(hdsp); 4838 if (err < 0) 4839 return err; 4840 } 4841 memset(&hdsp_version, 0, sizeof(hdsp_version)); 4842 hdsp_version.io_type = hdsp->io_type; 4843 hdsp_version.firmware_rev = hdsp->firmware_rev; 4844 if (copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))) 4845 return -EFAULT; 4846 break; 4847 } 4848 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: { 4849 struct hdsp_firmware firmware; 4850 u32 __user *firmware_data; 4851 int err; 4852 4853 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; 4854 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */ 4855 if (hdsp->io_type == Undefined) return -EINVAL; 4856 4857 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded)) 4858 return -EBUSY; 4859 4860 dev_info(hdsp->card->dev, 4861 "initializing firmware upload\n"); 4862 if (copy_from_user(&firmware, argp, sizeof(firmware))) 4863 return -EFAULT; 4864 firmware_data = (u32 __user *)firmware.firmware_data; 4865 4866 if (hdsp_check_for_iobox (hdsp)) 4867 return -EIO; 4868 4869 if (!hdsp->fw_uploaded) { 4870 hdsp->fw_uploaded = vmalloc(HDSP_FIRMWARE_SIZE); 4871 if (!hdsp->fw_uploaded) 4872 return -ENOMEM; 4873 } 4874 4875 if (copy_from_user(hdsp->fw_uploaded, firmware_data, 4876 HDSP_FIRMWARE_SIZE)) { 4877 err = -EFAULT; 4878 goto free_fw_uploaded; 4879 } 4880 4881 hdsp->state |= HDSP_FirmwareCached; 4882 4883 err = snd_hdsp_load_firmware_from_cache(hdsp); 4884 if (err < 0) 4885 goto free_fw_uploaded; 4886 4887 if (!(hdsp->state & HDSP_InitializationComplete)) { 4888 err = snd_hdsp_enable_io(hdsp); 4889 if (err < 0) 4890 goto free_fw_uploaded; 4891 4892 snd_hdsp_initialize_channels(hdsp); 4893 snd_hdsp_initialize_midi_flush(hdsp); 4894 4895 err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp); 4896 if (err < 0) { 4897 dev_err(hdsp->card->dev, 4898 "error creating alsa devices\n"); 4899 goto free_fw_uploaded; 4900 } 4901 } 4902 break; 4903 } 4904 case SNDRV_HDSP_IOCTL_GET_MIXER: { 4905 struct hdsp_mixer __user *mixer = (struct hdsp_mixer __user *)argp; 4906 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE)) 4907 return -EFAULT; 4908 break; 4909 } 4910 default: 4911 return -EINVAL; 4912 } 4913 return 0; 4914 free_fw_uploaded: 4915 vfree(hdsp->fw_uploaded); 4916 hdsp->fw_uploaded = NULL; > 4917 err: > 4918 return err; 4919 } 4920
Hi Zhipeng, kernel test robot noticed the following build warnings: [auto build test WARNING on tiwai-sound/for-next] [also build test WARNING on tiwai-sound/for-linus linus/master v6.7-rc7 next-20231222] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in 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/20231225-155210 base: https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next patch link: https://lore.kernel.org/r/20231224082533.3540468-1-alexious%40zju.edu.cn patch subject: [PATCH] ALSA: hdsp: fix some memleaks in snd_hdsp_hwdep_ioctl config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20231226/202312260721.mfXz0imt-lkp@intel.com/config) compiler: alpha-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231226/202312260721.mfXz0imt-lkp@intel.com/reproduce) 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> | Closes: https://lore.kernel.org/oe-kbuild-all/202312260721.mfXz0imt-lkp@intel.com/ All warnings (new ones prefixed by >>): sound/pci/rme9652/hdsp.c: In function 'snd_hdsp_hwdep_ioctl': >> sound/pci/rme9652/hdsp.c:4917:1: warning: label 'err' defined but not used [-Wunused-label] 4917 | err: | ^~~ vim +/err +4917 sound/pci/rme9652/hdsp.c 4727 4728 static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg) 4729 { 4730 struct hdsp *hdsp = hw->private_data; 4731 void __user *argp = (void __user *)arg; 4732 int err; 4733 4734 switch (cmd) { 4735 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: { 4736 struct hdsp_peak_rms __user *peak_rms = (struct hdsp_peak_rms __user *)arg; 4737 4738 err = hdsp_check_for_iobox(hdsp); 4739 if (err < 0) 4740 return err; 4741 4742 err = hdsp_check_for_firmware(hdsp, 1); 4743 if (err < 0) 4744 return err; 4745 4746 if (!(hdsp->state & HDSP_FirmwareLoaded)) { 4747 dev_err(hdsp->card->dev, 4748 "firmware needs to be uploaded to the card.\n"); 4749 return -EINVAL; 4750 } 4751 4752 switch (hdsp->io_type) { 4753 case H9652: 4754 return hdsp_9652_get_peak(hdsp, peak_rms); 4755 case H9632: 4756 return hdsp_9632_get_peak(hdsp, peak_rms); 4757 default: 4758 return hdsp_get_peak(hdsp, peak_rms); 4759 } 4760 } 4761 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: { 4762 struct hdsp_config_info info; 4763 unsigned long flags; 4764 int i; 4765 4766 err = hdsp_check_for_iobox(hdsp); 4767 if (err < 0) 4768 return err; 4769 4770 err = hdsp_check_for_firmware(hdsp, 1); 4771 if (err < 0) 4772 return err; 4773 4774 memset(&info, 0, sizeof(info)); 4775 spin_lock_irqsave(&hdsp->lock, flags); 4776 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp); 4777 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp); 4778 if (hdsp->io_type != H9632) 4779 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp); 4780 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp); 4781 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632) ? 3 : 1); ++i) 4782 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i); 4783 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp); 4784 info.spdif_out = (unsigned char)hdsp_toggle_setting(hdsp, 4785 HDSP_SPDIFOpticalOut); 4786 info.spdif_professional = (unsigned char) 4787 hdsp_toggle_setting(hdsp, HDSP_SPDIFProfessional); 4788 info.spdif_emphasis = (unsigned char) 4789 hdsp_toggle_setting(hdsp, HDSP_SPDIFEmphasis); 4790 info.spdif_nonaudio = (unsigned char) 4791 hdsp_toggle_setting(hdsp, HDSP_SPDIFNonAudio); 4792 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp); 4793 info.system_sample_rate = hdsp->system_sample_rate; 4794 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp); 4795 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp); 4796 info.clock_source = (unsigned char)hdsp_clock_source(hdsp); 4797 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp); 4798 info.line_out = (unsigned char) 4799 hdsp_toggle_setting(hdsp, HDSP_LineOut); 4800 if (hdsp->io_type == H9632) { 4801 info.da_gain = (unsigned char)hdsp_da_gain(hdsp); 4802 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp); 4803 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp); 4804 info.xlr_breakout_cable = 4805 (unsigned char)hdsp_toggle_setting(hdsp, 4806 HDSP_XLRBreakoutCable); 4807 4808 } else if (hdsp->io_type == RPM) { 4809 info.da_gain = (unsigned char) hdsp_rpm_input12(hdsp); 4810 info.ad_gain = (unsigned char) hdsp_rpm_input34(hdsp); 4811 } 4812 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) 4813 info.analog_extension_board = 4814 (unsigned char)hdsp_toggle_setting(hdsp, 4815 HDSP_AnalogExtensionBoard); 4816 spin_unlock_irqrestore(&hdsp->lock, flags); 4817 if (copy_to_user(argp, &info, sizeof(info))) 4818 return -EFAULT; 4819 break; 4820 } 4821 case SNDRV_HDSP_IOCTL_GET_9632_AEB: { 4822 struct hdsp_9632_aeb h9632_aeb; 4823 4824 if (hdsp->io_type != H9632) return -EINVAL; 4825 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS; 4826 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS; 4827 if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb))) 4828 return -EFAULT; 4829 break; 4830 } 4831 case SNDRV_HDSP_IOCTL_GET_VERSION: { 4832 struct hdsp_version hdsp_version; 4833 int err; 4834 4835 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; 4836 if (hdsp->io_type == Undefined) { 4837 err = hdsp_get_iobox_version(hdsp); 4838 if (err < 0) 4839 return err; 4840 } 4841 memset(&hdsp_version, 0, sizeof(hdsp_version)); 4842 hdsp_version.io_type = hdsp->io_type; 4843 hdsp_version.firmware_rev = hdsp->firmware_rev; 4844 if (copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))) 4845 return -EFAULT; 4846 break; 4847 } 4848 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: { 4849 struct hdsp_firmware firmware; 4850 u32 __user *firmware_data; 4851 int err; 4852 4853 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; 4854 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */ 4855 if (hdsp->io_type == Undefined) return -EINVAL; 4856 4857 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded)) 4858 return -EBUSY; 4859 4860 dev_info(hdsp->card->dev, 4861 "initializing firmware upload\n"); 4862 if (copy_from_user(&firmware, argp, sizeof(firmware))) 4863 return -EFAULT; 4864 firmware_data = (u32 __user *)firmware.firmware_data; 4865 4866 if (hdsp_check_for_iobox (hdsp)) 4867 return -EIO; 4868 4869 if (!hdsp->fw_uploaded) { 4870 hdsp->fw_uploaded = vmalloc(HDSP_FIRMWARE_SIZE); 4871 if (!hdsp->fw_uploaded) 4872 return -ENOMEM; 4873 } 4874 4875 if (copy_from_user(hdsp->fw_uploaded, firmware_data, 4876 HDSP_FIRMWARE_SIZE)) { 4877 err = -EFAULT; 4878 goto free_fw_uploaded; 4879 } 4880 4881 hdsp->state |= HDSP_FirmwareCached; 4882 4883 err = snd_hdsp_load_firmware_from_cache(hdsp); 4884 if (err < 0) 4885 goto free_fw_uploaded; 4886 4887 if (!(hdsp->state & HDSP_InitializationComplete)) { 4888 err = snd_hdsp_enable_io(hdsp); 4889 if (err < 0) 4890 goto free_fw_uploaded; 4891 4892 snd_hdsp_initialize_channels(hdsp); 4893 snd_hdsp_initialize_midi_flush(hdsp); 4894 4895 err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp); 4896 if (err < 0) { 4897 dev_err(hdsp->card->dev, 4898 "error creating alsa devices\n"); 4899 goto free_fw_uploaded; 4900 } 4901 } 4902 break; 4903 } 4904 case SNDRV_HDSP_IOCTL_GET_MIXER: { 4905 struct hdsp_mixer __user *mixer = (struct hdsp_mixer __user *)argp; 4906 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE)) 4907 return -EFAULT; 4908 break; 4909 } 4910 default: 4911 return -EINVAL; 4912 } 4913 return 0; 4914 free_fw_uploaded: 4915 vfree(hdsp->fw_uploaded); 4916 hdsp->fw_uploaded = NULL; > 4917 err: 4918 return err; 4919 } 4920
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c index e7d1b43471a2..6f6add2f7c42 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; +err: + return err; } static const struct snd_pcm_ops snd_hdsp_playback_ops = {