Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp642564pxj; Thu, 13 May 2021 13:21:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwB8/3AnDgr60BRhw4V1URXOmwLFiZRvtSputVXVVTDAVw5s4EiJPLIayfRCppCIZ+5SJVM X-Received: by 2002:a17:906:8299:: with SMTP id h25mr1037683ejx.81.1620937284135; Thu, 13 May 2021 13:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620937284; cv=none; d=google.com; s=arc-20160816; b=aFm1UI+kgHi7zBQICIIjKBu61QoaPUPUtHZvfEhyWHvorYv03ZjQUGPYo04Xg6nZDG V3X9/DQINA4/kwCkOBKlJ8OpGoZUHX1ryqixhIx7KvZM3PytBW0XQjzFWpyFqhoct53F 6JIZ428pEiHrNVwsusGnFVPrsdMTbC/nZ23nV4v6WeSJFsZAz7VV0U4hqT5KNpa27j5i BapXos5va+rgbvtCIU/pk6FQ5GGotXkYdF4YQjGYdrKFLgCeOSrfykCVPxCUYcEtQh+f lU8iLIUdNOLQOj/nx1CShPfxxDkrj+juH5zsXZ8vihKrWuB1fEyUXROzV28k5jP2qCdE WWqA== 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=MlVahHcRzJl/OmCKvY8N8NXLgxaRCwf7xRO5a1v6DG4=; b=rr80kNl5VkzL+AWjMXnfkhCqtbYe+ItoPeHeMGY6xh9aXIWvsgvSmoFLhnycFrRs+G 6fjvlQ3x0Jys4HmtOhVj6x4GBsCs0zkeUrptNQaqPUhdMbvRKF+AHMOiK1FoJnWDgAoi AQFbvtRsC1jI6VH6U0KckHHt1Uui54b4SuwbAfPuNYvwTVEMa0DQPn/qoSheze4KS6W3 Kgtss5nkFRPWk90pwCsNpgh1CgZ5TLGHbG88QlN2w5W4XZJ4LNG0QkEMz6KFvFX9y5sY BfRPN8Td5wJ2dd18zKqe/LBcwg6fuhYrPqj2KhxAp7l3vAMIWJCdC+joOJZS373VDxVF RMsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b="j/pXCq7y"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r9si2326831edw.304.2021.05.13.13.20.33; Thu, 13 May 2021 13:21:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b="j/pXCq7y"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233731AbhEMMKZ (ORCPT + 99 others); Thu, 13 May 2021 08:10:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233683AbhEMMJN (ORCPT ); Thu, 13 May 2021 08:09:13 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3BD2C06174A for ; Thu, 13 May 2021 05:08:01 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id df21so3467856edb.3 for ; Thu, 13 May 2021 05:08:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MlVahHcRzJl/OmCKvY8N8NXLgxaRCwf7xRO5a1v6DG4=; b=j/pXCq7yyKY2f3i6cvIOBs189d76MN7wr/olH2qy9H1hTBYAcVTHQcKa/pAa+1yG2W CX9v59oLtDFskHC8wxRmy1SvnGLLcMA+Sw8etHN0ynspW5m/I3p8vYC0a9YYcc8eM8Tz zpFeZ/O/btnvhlQCqlw/vRa18JWZi8QYUCTkrjHXBdqNnFBEpPyHU1+MUBxyepj2rGnU fnlNflUysjK70JdP0wIH1MWyW5xmyGMShICoo8YPQs49x3erVZ7KOb/bZDTJDS1maw9g AliHKRjfuieLfpAUTRG+nHYl6YqwKrZ9y5PDTmtcgx4Uf6VVLSq58lRKKOCpuTwvoxzW OZmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MlVahHcRzJl/OmCKvY8N8NXLgxaRCwf7xRO5a1v6DG4=; b=VjePa8+J/HvAvjLFQxf4iMfQBdKy6qS+PubWO5kTPN+saQ2sdEP8MHnnolBz8pSQcH 7sPaa7nXbnmq8rsfsaASXPiZM4DdjQyxjJzzuIVxcquP6elBQ71OIIsiDLqaMwygCWJ5 dYJ1SSPciBNET/D412ImVJq7eJ84LHdla7yR+krirBLD8cK0lickyMvVPebgtqidLEpA FVzvtFMS0HeITNzFHQABstwNXWTiqs/qogs3QZo6LC51/E3KPRTiOpk4cT7OOSAFx5RW DNHZFPof1c4CeOv4NX8kwbQK+4/QcesLSAvmHyziqMmlM8fJ0ncP9Xih3cwUhXSx5Z1y rvJQ== X-Gm-Message-State: AOAM533vuZtzuEWtrm7gWe2UhVaO5bHDik2b9Awze+YwnGG6bK+kl9+J IRVDnWpE8d86PmXLiU4ko3bYXg== X-Received: by 2002:aa7:d6c6:: with SMTP id x6mr49115549edr.193.1620907680776; Thu, 13 May 2021 05:08:00 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id ga28sm1717809ejc.20.2021.05.13.05.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 05:08:00 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean , Alexandru Ardelean Subject: [PATCH v4 02/12] iio: adc: ad7124: Fix potential overflow due to non sequential channel numbers Date: Thu, 13 May 2021 15:07:42 +0300 Message-Id: <20210513120752.90074-3-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210513120752.90074-1-aardelean@deviqon.com> References: <20210513120752.90074-1-aardelean@deviqon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Cameron Channel numbering must start at 0 and then not have any holes, or it is possible to overflow the available storage. Note this bug was introduced as part of a fix to ensure we didn't rely on the ordering of child nodes. So we need to support arbitrary ordering but they all need to be there somewhere. Note I hit this when using qemu to test the rest of this series. Arguably this isn't the best fix, but it is probably the most minimal option for backporting etc. Fixes: d7857e4ee1ba6 ("iio: adc: ad7124: Fix DT channel configuration") Reviewed-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7124.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index 437116a07cf1..a27db78ea13e 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -771,6 +771,13 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev, if (ret) goto err; + if (channel >= indio_dev->num_channels) { + dev_err(indio_dev->dev.parent, + "Channel index >= number of channels\n"); + ret = -EINVAL; + goto err; + } + ret = of_property_read_u32_array(child, "diff-channels", ain, 2); if (ret) -- 2.31.1