From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5574C43334 for ; Wed, 6 Jul 2022 10:01:17 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id E91C716B8; Wed, 6 Jul 2022 12:00:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E91C716B8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1657101676; bh=v5Jtw8TNJ86g2xK++XtxFf439WA0tQUMSwkUzcPYJD8=; h=Date:Subject:From:To:References:In-Reply-To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Kk81Bu6oXm9XJkImlaPrSzCoHMD2YBUYMqyxi9uJV6H911fh2+1LIpgRfHjRkcK4z OvQsxTcwSYFTx/qdUFFSiYe+aKlJEMtR/FgiHiIzqhlj1zpwYMpMKCMr/kinM1hDqp Aa6WHtbQbilq2msb1z2jXXvKh83+4OSYMrmvFMWA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 90B3CF8016B; Wed, 6 Jul 2022 12:00:25 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 66027F8032B; Wed, 6 Jul 2022 12:00:24 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 77393F8012A; Wed, 6 Jul 2022 12:00:16 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 77393F8012A Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="iq+IiRE/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657101622; x=1688637622; h=message-id:date:mime-version:subject:from:to:cc: references:in-reply-to:content-transfer-encoding; bh=v5Jtw8TNJ86g2xK++XtxFf439WA0tQUMSwkUzcPYJD8=; b=iq+IiRE/3EAfpdqkR2Pjp0m7nzU/8eM6iKOLOQELG5bW19dd9zs3MByH I4Wzbpbmvxn0qXMxLhAWulVJX2CnSzETZO/enyYvIdsAHyyM0VdLLdJlg 8KeqOdTFjQjSAImpG01+nxOHEtap/pG5UKdrLTXYgrKbGFAzgie8zwQJf ZF/qLrNyLmu7ZVDDjRNG+DObYGEZHkHq+lJiQaWzZmmsNPIp3q5VKI9IX 8VS7G5DaBJAHan5NA1e5HgtakVFxlVIpKcZDN1nHbsMe1cBwWULDLyyRt TDJf3zTrmx/J+ZHmZnTZxX1T+TyHzjcrDFdHtbXzs9ASMtzSU4F7IOSLK Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="282452676" X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="282452676" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 03:00:01 -0700 X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="920098852" Received: from gguerra-mobl1.ger.corp.intel.com (HELO [10.249.254.46]) ([10.249.254.46]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 02:59:58 -0700 Message-ID: <61def9b6-b6bf-c2c0-2a75-54d10003c7ca@linux.intel.com> Date: Wed, 6 Jul 2022 13:00:44 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.10.0 Subject: Re: [PATCH 1/2] ASoC: SOF: sof-client-probes: fix error codes in sof_probes_compr_copy() Content-Language: en-US From: =?UTF-8?Q?P=c3=a9ter_Ujfalusi?= To: Dan Carpenter , Pierre-Louis Bossart References: <26db7e60-51d1-444a-7620-8225239ad7bf@linux.intel.com> In-Reply-To: <26db7e60-51d1-444a-7620-8225239ad7bf@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: alsa-devel@alsa-project.org, Kai Vehmanen , Daniel Baluta , kernel-janitors@vger.kernel.org, Takashi Iwai , Liam Girdwood , Mark Brown , Ranjani Sridharan , Bard Liao , sound-open-firmware@alsa-project.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On 06/07/2022 12:05, Péter Ujfalusi wrote: > > > On 06/07/2022 10:23, Dan Carpenter wrote: >> This function tries to return the number of bytes that it was able to >> copy to the user. However, because there are multiple calls to >> copy_to_user() in a row that means the bytes are not necessarily >> consecutive so it's not useful. Just return -EFAULT instead. > > The function is copying data from a circular buffer to a use buffer. > The single copy_to_user() is used when we don't have wrapping, the > 'double' copy_to_user() is when we wrap, so first copy is from the end > of the buffer then we copy the data from the start of the buffer to get > all data. What I wanted to say is that the original code is correct, this patch would break the functionality. > >> Fixes: 3dc0d7091778 ("ASoC: SOF: Convert the generic probe support to SOF client") >> Signed-off-by: Dan Carpenter >> --- >> sound/soc/sof/sof-client-probes.c | 12 ++++++------ >> 1 file changed, 6 insertions(+), 6 deletions(-) >> >> diff --git a/sound/soc/sof/sof-client-probes.c b/sound/soc/sof/sof-client-probes.c >> index 1f1ea93a7fbf..679bc7d371fc 100644 >> --- a/sound/soc/sof/sof-client-probes.c >> +++ b/sound/soc/sof/sof-client-probes.c >> @@ -385,7 +385,6 @@ static int sof_probes_compr_copy(struct snd_soc_component *component, >> struct snd_compr_runtime *rtd = cstream->runtime; >> unsigned int offset, n; >> void *ptr; >> - int ret; >> >> if (count > rtd->buffer_size) >> count = rtd->buffer_size; >> @@ -395,14 +394,15 @@ static int sof_probes_compr_copy(struct snd_soc_component *component, >> n = rtd->buffer_size - offset; >> >> if (count < n) { >> - ret = copy_to_user(buf, ptr, count); >> + if (copy_to_user(buf, ptr, count)) >> + return -EFAULT; >> } else { >> - ret = copy_to_user(buf, ptr, n); >> - ret += copy_to_user(buf + n, rtd->dma_area, count - n); >> + if (copy_to_user(buf, ptr, n)) >> + return -EFAULT; >> + if (copy_to_user(buf + n, rtd->dma_area, count - n)) >> + return -EFAULT; >> } >> >> - if (ret) >> - return count - ret; >> return count; >> } >> > -- Péter