Message ID | 20230523151223.109551-4-herve.codina@bootlin.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp2202225rwl; Tue, 23 May 2023 08:16:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6zJGLP9x1vcFRfh/yhO/xXdf8FXAl5nZjeC8Yn98SvfLXfJMVMuINC97UuBw/io6G3Kte8 X-Received: by 2002:a05:6a21:998f:b0:10a:be5c:6e26 with SMTP id ve15-20020a056a21998f00b0010abe5c6e26mr12229623pzb.3.1684854967411; Tue, 23 May 2023 08:16:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684854967; cv=none; d=google.com; s=arc-20160816; b=rc0OhbyXU19Kz1PgrBOrkvzhgncsN8iFFqlpeBceiN7SDGX7WkgtnA7sHFOemX95Q9 CQKWJsnYxzyHy4FU00epusxUZ0iwzjA9FBkwk2pAZwk25mhG9h6YXx6Y8yMAUT2Lssy7 nsDcy2mIun0GBBEHqh+gJ+4+5ocXn8Uj9rgFlTyI8XWqU2dp9xntCMoyDhQfzqV75zh6 6bwQzhxR64yZ/GAzLg6FSkFpyqbzkvAB9ivHcztGHxmmaEZIykfyR3LMY1ORdy8DVHN5 HJfayG8I6IBm//ADfqoIeNs219odEINfNnna87dIrbunwvwlJY8MgsqOZm4cPwQRBMIZ MtCw== 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=iaB/0wDo6caLF16LcGUil+N2SlVgAqTWL0MVlJHk1e0=; b=E63LcNfBXMGlI+q/AcUeujoOIY7ZOqMebeifn6m8LTy8ENBGzEr/gIVBGg9zVoaGeg ORafP/urDEdB68MpuvPKWw4Xt4+WJYdVNc/sZq6YIiQ0+Gx1wO2/qHm9tJCQdlFgSbB7 QFgXJH+oKkRuZ2zAjJBECgrxNA5h/1Y3WROw3h4o2INsIbPASIDt2+Ux6fMHmdFtlJpN 4DwuRk4FSjwfT/nHYXzlNFUNcT2gb8NKD7eeXdKDz0OKDSmqvtR8nkfpkc857doW0DM+ j/Ya07qXamAePbyNQvkf30H22v+GadEcrkmLtrS04v/XWxnlv+gCoxDrknZdtrT8gCQF f8Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=SHHtcMfh; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g186-20020a6252c3000000b0064d44f6fd24si6488650pfb.56.2023.05.23.08.15.54; Tue, 23 May 2023 08:16:07 -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=SHHtcMfh; 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 S236996AbjEWPMw (ORCPT <rfc822;ahmedalshaiji.dev@gmail.com> + 99 others); Tue, 23 May 2023 11:12:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237458AbjEWPMq (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 23 May 2023 11:12:46 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C49DA139; Tue, 23 May 2023 08:12:43 -0700 (PDT) Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id C2404C000C; Tue, 23 May 2023 15:12:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1684854762; 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=iaB/0wDo6caLF16LcGUil+N2SlVgAqTWL0MVlJHk1e0=; b=SHHtcMfh8AILZzywUiY+JuAsqPsBNtIXcI99+1kFaoQx5tj45NNugTxMOGHKc9hsTpwRQt rekNusNg0UOA9IZBQjhpH6EnJljUKPtYlMsujlxrj9Pdi8NLBEzE5+3kImsVnYjIwY8hwH tFx7JS/y8wGDFj3ki1R0Gg3gk8tqZ1KTbXxxm6netGuSSOd1LxYP/puO8boVlj/KFEbNEQ tTcDj0Xb17GTmOJX/tWtfSzWYp1vX4LV6zx3Vs64lntAwgGStP3ZRyP489WiO7pyKuVLbV /rnhF87CmiYy8fNos+Ria3POWqavMpiBPD1d7l1w4hcgPh9m46SMxDrE/jy1vg== From: Herve Codina <herve.codina@bootlin.com> To: Herve Codina <herve.codina@bootlin.com>, Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Jonathan Cameron <jic23@kernel.org>, Lars-Peter Clausen <lars@metafoo.de>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy <christophe.leroy@csgroup.eu>, Thomas Petazzoni <thomas.petazzoni@bootlin.com> Subject: [PATCH v2 3/9] iio: inkern: Check error explicitly in iio_channel_read_max() Date: Tue, 23 May 2023 17:12:17 +0200 Message-Id: <20230523151223.109551-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523151223.109551-1-herve.codina@bootlin.com> References: <20230523151223.109551-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_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766698482238446318?= X-GMAIL-MSGID: =?utf-8?q?1766698482238446318?= |
Series |
Add support for IIO devices in ASoC
|
|
Commit Message
Herve Codina
May 23, 2023, 3:12 p.m. UTC
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 <herve.codina@bootlin.com>
---
drivers/iio/inkern.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
On Tue, 23 May 2023 17:12:17 +0200 Herve Codina <herve.codina@bootlin.com> wrote: > 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 <herve.codina@bootlin.com> It's an odd code construct, so in the interests of robustness this looks like a good improvement to me. Given the later patch you need for this series will see some fuzz I think if I pick this up separately I'll currently assume this whole series will go together. Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > --- > 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; > } > } >
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; } }