Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5472602rwd; Mon, 12 Jun 2023 05:46:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5XMJQZ5SRVHsyO8DjjAQRQWfbR0Q+htE3148cgd5Jzmkf8ihR2d6m4K9rIMS4/lcfX1KsR X-Received: by 2002:a17:907:9412:b0:978:6e73:e833 with SMTP id dk18-20020a170907941200b009786e73e833mr8871278ejc.45.1686573991877; Mon, 12 Jun 2023 05:46:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686573991; cv=none; d=google.com; s=arc-20160816; b=u01IR50nN4Wx/dnNPjhjkIxP7h84khiPLoEzjdBrBQmv0F+e53oRb4bm4yZFChXcC1 SyA3D/66Jwt5pnDUD6AzUMDWQiZVc2N0ZxpUfNIrMlfjRzhXTSPcjWfNCazhjvSRcfk/ MoJjiGEvvHReN0uaiagZM0Ya+VhBP6gsjYPkFjL+67U0/nSe+lFrAo5RKYS8L2haulJ0 VEOeymnU//gOQGk+sakH2wbasIJpW6uGCIZZ6tp5ShC9Q0E/jJQKevpey1reKc/b/i2M g7TW2YcBusHYvRxKvBMr/yU93NWsCy3pgZ+Dft6hIBT7wuaTn2fjNNE/34ObVgzXJ2rH Ff9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fxihK5WvOxWe3kLHHpt2g1PiNniemigSf5773LJSuNI=; b=mb9d7Td97isfFGnlVy/yfMmDX+VKECcml6WyDOzBhUovNoPj3o6kr1ZU4Y0ANgo4cD 1BmmPSOYMfcxuSOyDoIX3gELzfznqwSIm4DL0/1OPkIDTWsu4Nb4YvAwRFTaTJOhNrbY wP9vvJa2SLTs9f+ni/+4W2+Pz0gM+tujgPWjgX4wglv97KllZskOq/ya0/kbby0PFZ8B j5gsCzzpQbt7NNwRt2R63NAZ6k9p680TOGTa+aTLlVnuSK+36zVjeRuzFfRHri64GAoI 0+pnvVfPn0p6dO5b/PPxh/NTK6EJwO4f5FIt9XcQiorSI0kGYwnXqd9EI7bABmg+RFQ4 sbhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=C8wzreCD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p9-20020a170906614900b00977cc3d4bf2si5056582ejl.1007.2023.06.12.05.46.05; Mon, 12 Jun 2023 05:46:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=C8wzreCD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232732AbjFLMaT (ORCPT + 99 others); Mon, 12 Jun 2023 08:30:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233344AbjFLMaD (ORCPT ); Mon, 12 Jun 2023 08:30:03 -0400 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B92FA98; Mon, 12 Jun 2023 05:30:01 -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=1686573000; 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=fxihK5WvOxWe3kLHHpt2g1PiNniemigSf5773LJSuNI=; b=C8wzreCDiLenUXn7Nb6eOorDJJoB3hl00Lr0jwbMl1swMv5DC73t/KbiZ5RSaU1smiXbpB SYGduS0pAUP4IVMsmy4gdjr0gqVLR5leEB9u+Ii0rGmz08o6Gn3wZpGDofnXXC97b1FnO6 jOJzc4sBnHMPyKlcJrYmXnI6X9XLzyTsQ6H0X82U/j/dnsYanuuHAYLyb2NGwRXqiiHdwY 1Pe28U2Bjgav0LDJRQhur5BSIep73UQzt1ImOzXwwDzmm2U2GdPwtccKjIqx9qZK2vFFOY 2jZbdZmLk0qITHHJEmpUTvUdzLSn8kylw09vCD4I4rrmsjEZJseDv1vUTMG16A== 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 4E632240018; Mon, 12 Jun 2023 12:29:58 +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 v3 03/12] iio: inkern: Check error explicitly in iio_channel_read_max() Date: Mon, 12 Jun 2023 14:29:17 +0200 Message-Id: <20230612122926.107333-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612122926.107333-1-herve.codina@bootlin.com> References: <20230612122926.107333-1-herve.codina@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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; } } -- 2.40.1