From patchwork Thu Jun 15 15:26:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 693278 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 72AECEB64DA for ; Thu, 15 Jun 2023 15:28:57 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 64E76950; Thu, 15 Jun 2023 17:28:05 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 64E76950 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1686842935; bh=7e+7ZksAfL4pOgUmmUpF/ZpeR7gAdjp6+TumaVqnWzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=UmdBtS2nKiwGr8dYMNBqqrWgUWn9EvO5quwuEEypnT0lcDfB2koRvzKCWv5EGMOQj XR231LsFIw9G/EXDyG+H9Ki64bnlCDWw8zI/ubdgl3Y+Uo5IBoF/7pY16GTFhwhv8H PxFlXhsEtiAgSuBrYN+pk392lLfi26R6nTfEs+qQ= Received: by alsa1.perex.cz (Postfix, from userid 50401) id C34DBF8058C; Thu, 15 Jun 2023 17:26:56 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 0158FF8057D; Thu, 15 Jun 2023 17:26:55 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3F7C5F8025E; Thu, 15 Jun 2023 17:26:47 +0200 (CEST) Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id ED06CF80155 for ; Thu, 15 Jun 2023 17:26:41 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz ED06CF80155 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=DNkwSUbQ X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686842801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rfYOy7L85MdtcQ88k+lfhIIjhcOaxuYtKNcPHMwEQsI=; b=DNkwSUbQpzHsmovXfUt9+3hYNv8lCpGKZkIGNMH72ReCCWpw+SwUaY107imywc9IFOPHqX FjrkCczX3FJv6E/kjcNSw6DXTCGE5i9+mRdg89jn1h53WOChKq8umRZqDRu3lkiqOOXuTi 5btEtvVFHzdCNLyJPU6lQz3sWq1w7ZBWitlJ2Oi31jlHg5uhWGLntHxZuIv4LFwXyLGnOY tegR8uS9gANHOoUoYoLX8DG1fSD7Wnc52O3IzmB3f05ZsdKr7HjLEXHQtlNO4KU3K+xK1p WC53rkJUnFlGvs03zITB1ejOfp3lF58wei7nXm227iHlVPT4l8LE872S3r7RPQ== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 54A2CFF80B; Thu, 15 Jun 2023 15:26:39 +0000 (UTC) From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni , Jonathan Cameron Subject: [PATCH v5 03/13] iio: inkern: Check error explicitly in iio_channel_read_max() Date: Thu, 15 Jun 2023 17:26:21 +0200 Message-Id: <20230615152631.224529-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230615152631.224529-1-herve.codina@bootlin.com> References: <20230615152631.224529-1-herve.codina@bootlin.com> MIME-Version: 1.0 Message-ID-Hash: FVN7BGCNWCRBJMI7TN5PIN4JANOWVXR3 X-Message-ID-Hash: FVN7BGCNWCRBJMI7TN5PIN4JANOWVXR3 X-MailFrom: herve.codina@bootlin.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: <> List-Archive: <> List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The current implementation returns the error code as part of the default switch case. This can lead to returning an incorrect positive value in case of iio_avail_type enum entries evolution. In order to avoid this case, be more strict in error checking. Signed-off-by: Herve Codina Acked-by: Jonathan Cameron Reviewed-by: Andy Shevchenko --- drivers/iio/inkern.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 872fd5c24147..f738db9a0c04 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -858,6 +858,9 @@ static int iio_channel_read_max(struct iio_channel *chan, val2 = &unused; ret = iio_channel_read_avail(chan, &vals, type, &length, info); + if (ret < 0) + return ret; + switch (ret) { case IIO_AVAIL_RANGE: switch (*type) { @@ -888,7 +891,7 @@ static int iio_channel_read_max(struct iio_channel *chan, return 0; default: - return ret; + return -EINVAL; } }