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: 13281402 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DCCCEB64DA for ; Thu, 15 Jun 2023 15:27:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345221AbjFOP1P (ORCPT ); Thu, 15 Jun 2023 11:27:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343959AbjFOP0o (ORCPT ); Thu, 15 Jun 2023 11:26:44 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 639CE2126; Thu, 15 Jun 2023 08:26:42 -0700 (PDT) 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 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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; } }