From patchwork Sun Sep 15 14:24:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 13804810 Received: from mout.web.de (mout.web.de [212.227.17.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA0D31C689D for ; Sun, 15 Sep 2024 14:25:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726410303; cv=none; b=Fx+N/5l6O0bnzFUnLGoJ28g2wH/tnJcb94GncjDx5a0B9Lb2xHf6q2SfsvVgU6DJnFuUBRCuA+AtCUbRmh09f4kvZjM3qape8ZI1EBs/QriCxo+hIsLXCrcogEXnAANNyo6e8IRUUVh0YjXaD3/lCAFXfMxZZxIaT99mIGdT9ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726410303; c=relaxed/simple; bh=r7g5ISWmixGL4QM8dWSHN7rNxA/iD7YudMraIZydYHU=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=aCQfdBo+3rdvoC+mXWB7IBXaeAfb3dfN7K/vVcIuFTYrVJzAF9pBs3n/P3EHjg4qrSUzHn9l4tns9BbjJ7zCbA3cIdLGvh132LU0+F1kTLLzECQivI+UjTrbDRIAkQWtves23PUs7rgLNRKwbTWMdYePV2kEHfzGF2ckZvdfwxA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b=dGlN9RLl; arc=none smtp.client-ip=212.227.17.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="dGlN9RLl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1726410273; x=1727015073; i=markus.elfring@web.de; bh=PJrESKbpxGlpgHq9AuoQQs6G3hzXBydYlXg7Swc3pe4=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:To:Cc:From: Subject:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=dGlN9RLliBiG/PgVIC6NBDiFC7bRXrE3R5z8Ch0M93PYpJwOinDZSsJm83xFVICH 6GXE06Nw4xae/p5hZhoisiBY4KaJt3GZk3SkPttLJPgUNjFAmKvR3eF0y96Choiim BdtZiomjW+9Pbp+zQxXxQQ6k81zJJKuBeAOahBtShMyjof10bA+cNK+sspDViVUOu UybPq1KRxwkkS8EvFwmtUWIAqX3S45ZBhNev/ir++fOW1N4VTBuBYw/uagved5eBv A4LDSPgwPnOllSQ7N8W0mbo3t/Sdi8HKSZWv6bN3QeL2wKaLuNyJtRnspyrct8VOF fl+JPlVyO3FMu2sY3g== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.85.95]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MqIFF-1sBoSQ2f0V-00nn3G; Sun, 15 Sep 2024 16:24:33 +0200 Message-ID: Date: Sun, 15 Sep 2024 16:24:25 +0200 Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: linux-sound@vger.kernel.org, Jaroslav Kysela , Takashi Iwai Content-Language: en-GB Cc: Julia Lawall From: Markus Elfring Subject: [PATCH] ALSA: emu10k1: Refactor copy_to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TxxxoubpBCPsIYGnJ6Nlk2tUM+kwsgcdxBkLgfSrBMMUtsloIsxwP3w04hFsCetsY4DdFiRm KC35Sy7Zy4tMmt7a3lAjtaxA== From: Markus Elfring Date: Sun, 15 Sep 2024 16:16:45 +0200 Assign values from selected expressions where copy_to_user() calls are involved to additional local variables so that the number of kfree() calls can be reduced accordingly. This issue was transformed by using the Coccinelle software. Signed-off-by: Markus Elfring --- sound/pci/emu10k1/emufx.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) -- 2.46.0 diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c index 03efc317e05f..2f20878a78c9 100644 --- a/sound/pci/emu10k1/emufx.c +++ b/sound/pci/emu10k1/emufx.c @@ -2496,12 +2496,12 @@ static int snd_emu10k1_fx8010_ioctl(struct snd_hwdep * hw, struct file *file, un if (!info) return -ENOMEM; snd_emu10k1_fx8010_info(emu, info); - if (copy_to_user(argp, info, sizeof(*info))) { + + { + unsigned long ctu = copy_to_user(argp, info, sizeof(*info)); kfree(info); - return -EFAULT; + return ctu ? -EFAULT : 0; } - kfree(info); - return 0; case SNDRV_EMU10K1_IOCTL_CODE_POKE: if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -2517,12 +2517,12 @@ static int snd_emu10k1_fx8010_ioctl(struct snd_hwdep * hw, struct file *file, un if (IS_ERR(icode)) return PTR_ERR(icode); res = snd_emu10k1_icode_peek(emu, icode); - if (res == 0 && copy_to_user(argp, icode, sizeof(*icode))) { + + { + bool ctu = res == 0 && copy_to_user(argp, icode, sizeof(*icode)); kfree(icode); - return -EFAULT; + return ctu ? -EFAULT : res; } - kfree(icode); - return res; case SNDRV_EMU10K1_IOCTL_PCM_POKE: ipcm = memdup_user(argp, sizeof(*ipcm)); if (IS_ERR(ipcm)) @@ -2535,12 +2535,12 @@ static int snd_emu10k1_fx8010_ioctl(struct snd_hwdep * hw, struct file *file, un if (IS_ERR(ipcm)) return PTR_ERR(ipcm); res = snd_emu10k1_ipcm_peek(emu, ipcm); - if (res == 0 && copy_to_user(argp, ipcm, sizeof(*ipcm))) { + + { + bool ctu = res == 0 && copy_to_user(argp, ipcm, sizeof(*ipcm)); kfree(ipcm); - return -EFAULT; + return ctu ? -EFAULT : res; } - kfree(ipcm); - return res; case SNDRV_EMU10K1_IOCTL_TRAM_SETUP: if (!capable(CAP_SYS_ADMIN)) return -EPERM;