From patchwork Wed Jun 14 07:48:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 107775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1067139vqr; Wed, 14 Jun 2023 00:52:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ54yLbAkJllMC9yJzDt2+V9AhTnfCmvVAYP5cSmMtUsqbPF/YMs3ZTIQetEgukO8lVV+k26 X-Received: by 2002:a17:907:9621:b0:96f:8afc:b310 with SMTP id gb33-20020a170907962100b0096f8afcb310mr898802ejc.3.1686729164021; Wed, 14 Jun 2023 00:52:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686729164; cv=none; d=google.com; s=arc-20160816; b=MHlrSlKast9HjMvqAMqogyexLDX7XuLr8m4I/OSAHxCUpZdUE03Q3mhEB3dgb/05UC LVjUM9sNC/VTleP8rjOwKUgFC1b2ad6hoOAFOCnQoavFAovhhRgKtMvzkAMP0i5fWvcB Mwsw/oRb0pdSiWrrV5zdRO0740XIiqnaY/0zyvwr6poysGHx7xk8j1HUFtlrfBoruF3d J51SofV56lD3hXMWuIpQYFFMobl2bSnVkjMVg+DbrQ26IfvG2BGcKmr+Oq8THp8chiZF cIW2nAlfhfneIGOwnuTBfMaupkV1mv0zvhthQjm2HliQRqtjmhxp7JW9QojNOBrTnDJk r5Dg== 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=FkQZxmbGPKkjmBtgt+Imn8A43/IEec3F3481+44qF+k=; b=UT9BqZMAzsqeXdAE1pg2RpGSNQzWx+Tv//AxxVjuYWPerPrhWSb6v+E/lrULLfBVaX 02AmYETYY04rcMWQ8qTSnOGTeMu9Z+ypTsxEE4ETziuJL7LAjtxNJCbvYx2/5J1IK9V5 11JnaIPURrYp9FUwtZQJ0SfJjGJcL/oUxjZamV5Myg4E8lcekUOKpLbEnOuRBXgM2tZ7 lbHfggZM0tGcu9k9IKonodabIv4jRCSVgFyz8zABGYAp3FIgkU1YEH9tOd0tufQSM9XQ UW9+BjfhYA8PID6RTByWIRNZrNdDhOgJ8WeKyTK+KpIwrlAhSsuIcJSrmh1YCVqjWbMh KFUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Ujb6byVz; 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 o12-20020a170906358c00b00977cc7821cfsi8052755ejb.891.2023.06.14.00.52.19; Wed, 14 Jun 2023 00:52:44 -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=Ujb6byVz; 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 S243519AbjFNHuf (ORCPT + 99 others); Wed, 14 Jun 2023 03:50:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243354AbjFNHtj (ORCPT ); Wed, 14 Jun 2023 03:49:39 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E09E1BC5; Wed, 14 Jun 2023 00:49:37 -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=1686728975; 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=FkQZxmbGPKkjmBtgt+Imn8A43/IEec3F3481+44qF+k=; b=Ujb6byVz6xAJtqKOMKEQtjG3xe6iIYKPGrHEfXRwBlClFYHJ/p+0jTKy02C1Q286OKL/SZ ILQgzNF6pej6fg81ryl6Q9t7iU3DB77LvHCbuhsMSoUn06yUmqk3PdXmIZnfYTKJ/sGuly S/2POfPSxQuIqoIxdQaEsQUGWCkMeOrCoCnXJ+lA17w+kAx8Q3F2yjiV4xqpAXr9NTzgsY f6OVZo+5oe8+/bpa0OTdRsWxdr1+Ixp2XSxJyTTpX3+dQO4eo2ZgsTtef/2M+6tYn1DxbM DZOAvrlDeqtksY9eu9cDE5iYn35vzntW0WdqKbHIC5j69PHIloHsvZFoFM2kjw== 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 9A1301C000D; Wed, 14 Jun 2023 07:49:34 +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 Subject: [PATCH v4 05/13] iio: inkern: Remove the 'unused' variable usage in iio_channel_read_max() Date: Wed, 14 Jun 2023 09:48:56 +0200 Message-Id: <20230614074904.29085-6-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614074904.29085-1-herve.codina@bootlin.com> References: <20230614074904.29085-1-herve.codina@bootlin.com> MIME-Version: 1.0 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,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768663719827880202?= X-GMAIL-MSGID: =?utf-8?q?1768663719827880202?= The code uses a local variable to initialize a null pointer in order to avoid accessing this null pointer later on. Simply removed the 'unused' variable and check for the null pointer just before accessing it. Signed-off-by: Herve Codina Reviewed-by: Andy Shevchenko --- drivers/iio/inkern.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index f738db9a0c04..ce537b4ca6ca 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -849,14 +849,10 @@ static int iio_channel_read_max(struct iio_channel *chan, int *val, int *val2, int *type, enum iio_chan_info_enum info) { - int unused; const int *vals; int length; int ret; - if (!val2) - val2 = &unused; - ret = iio_channel_read_avail(chan, &vals, type, &length, info); if (ret < 0) return ret; @@ -869,7 +865,8 @@ static int iio_channel_read_max(struct iio_channel *chan, break; default: *val = vals[4]; - *val2 = vals[5]; + if (val2) + *val2 = vals[5]; } return 0;