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 95F26CCA47C for ; Wed, 6 Jul 2022 09:05:58 +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 6072D1671; Wed, 6 Jul 2022 11:05:06 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6072D1671 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1657098356; bh=RfpzoH4hfqwhAmi1U0DrZ8kMnGeJ0kLgO1VmGWYJIK4=; h=Date:Subject:To:References:From:In-Reply-To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ucu+dKKIn2pkTnWgDFs4GyDZtNBWbboNN0v4VWUiiUFHj4C9gmkDZahruyR84N0Jt LMBh/YBGngExu3EWJHrb+Wzz2dk3RRqS1CH75rdqjiisJtdtoDy4BxnaAmxnzGiaT/ YalFcLUYt55YAYEElt8viVvjQmlvVicZJOigO20g= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id F1671F8016B; Wed, 6 Jul 2022 11:05:05 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id BBAE7F8023A; Wed, 6 Jul 2022 11:05:03 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 480E9F80104; Wed, 6 Jul 2022 11:04:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 480E9F80104 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UFl0d9HB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657098300; x=1688634300; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=RfpzoH4hfqwhAmi1U0DrZ8kMnGeJ0kLgO1VmGWYJIK4=; b=UFl0d9HB2qslfnpNy2oXZiZGP99FJ4gC8EjN3x5hoXFeEnBXnsz/SX5k BQEyGRczWYrDEeNYSOcI4jjHAibS2EkhENRRaFQgNICdaWORW6Lj0oFWY zibKVISlwmwU81ATL2nKzidbrk87qzlVyEw7NiNJWJ5KnhEHT9RiRVoIp ogV9TGHJXcCw3QF52V4KNm2HcGvopdh6+6xStXvoEVRdlkafdF23+ABxk kEPJkBJqeprq4gz41fV4/XnBvG/E2rAKpMzNet4SpYxSaQSGIxIS7QEL0 4QpaeKPBI3gwIXcATw1mkEE/mb11jkPBPk++l1jYyTxJLGthn0AZ1NyUP w==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="266717669" X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="266717669" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 02:04:54 -0700 X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="920080488" 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:04:50 -0700 Message-ID: <26db7e60-51d1-444a-7620-8225239ad7bf@linux.intel.com> Date: Wed, 6 Jul 2022 12:05:37 +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 To: Dan Carpenter , Pierre-Louis Bossart References: From: =?UTF-8?Q?P=c3=a9ter_Ujfalusi?= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: alsa-devel@alsa-project.org, Kai Vehmanen , Bard Liao , Takashi Iwai , kernel-janitors@vger.kernel.org, Liam Girdwood , Ranjani Sridharan , Mark Brown , Daniel Baluta , 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 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. > 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