Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp283367lqa; Sat, 27 Apr 2024 02:10:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVOvtwAmawO8h5QMOnt8jDq8+ld0SnMyrZp2zsMnO/Ic2f0NLtKaeEDuzUC0DdSTAzu6n7WSgCn6p5yo+qjS8ssQ7YQh1jHW2E78j4WiQ== X-Google-Smtp-Source: AGHT+IH7g8YAWimRZk25vIjcYzHQ5jEAmoR8bobYAfYfjCWu5Db32Zhi8u0Xv4pSjCDYCo7PbyP3 X-Received: by 2002:a17:90b:3d86:b0:2af:4f4e:79a7 with SMTP id pq6-20020a17090b3d8600b002af4f4e79a7mr5138376pjb.30.1714209000775; Sat, 27 Apr 2024 02:10:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714209000; cv=pass; d=google.com; s=arc-20160816; b=vymV/TqVKkxto/BegpSjSvCDMd0w2Gc+bbuoMASyX2NcKmDktT7G9uem69QsEckpp1 GaQhqk7K7T99bRuSEb7FFEBNghQXlwMr15JngoRUSdJ1QBPlYUxnTcd2rJC9WP+W82+3 gEdIpj/HVsO5nrg+sUaaCSPhODFm8OkfpIE4VJCxJoFv50DRfKTLwFcwBLkx7SD49pz9 8Un2F0801KH693jZ9ecwZod0sXWINbhG1s7syskuOLC49/nmYELxeCoj2m/3klUsR8jQ 6+8rryqV8wzlkLXbDztfqeG0E/ZzIvn5O119IuVcs4x4uxBI0e5JI5mCpLHIhC7KwnvM UyWQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=ynRU3BokI7x+TVZ0M1ndHqpxWwtn8+UGCy+jVf6kUXE=; fh=hp5SdmIE82PHJcrwaIa7TUmpfzvqEWASwVQwWyAC+Jo=; b=H1VBByxEk9eeqk2vGDKc2mfy25XWKBi1Xxwa9kgiNhfXJNT9zzxLgSg1h0yqrrDXO2 2TGg5AquRVNa8aLkHV4CdgOVdndSxyyfGCTgZVLFjyF2W/4vEb4v9YHX22bG1Cl6ETbt rqoR5e7mZkrIZuWoFy2yAs+4IEK19Cdf1pjPn0qxIl0E5+NnT9Kp3BjG494vn1+VHet8 fQ1XNJmbtKpWjzxhjUfE3HYvFegfNLX2N+rlWTdgh5T9XdEklnxMxp60xbz39OvfBk6R 1jta9ApXeR5N5gp5uqV2swPbA9qQmMU/v08e/YjV6q1yPEL7/LSEpRAZPAX0hrgimey7 JVkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tweaklogic.com header.s=google header.b=WQwUNZ4F; arc=pass (i=1 spf=pass spfdomain=tweaklogic.com dkim=pass dkdomain=tweaklogic.com); spf=pass (google.com: domain of linux-kernel+bounces-160970-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160970-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id hk17-20020a17090b225100b002b0da9ba990si944562pjb.186.2024.04.27.02.10.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Apr 2024 02:10:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160970-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@tweaklogic.com header.s=google header.b=WQwUNZ4F; arc=pass (i=1 spf=pass spfdomain=tweaklogic.com dkim=pass dkdomain=tweaklogic.com); spf=pass (google.com: domain of linux-kernel+bounces-160970-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160970-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3B4EC282E5A for ; Sat, 27 Apr 2024 09:10:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA78045959; Sat, 27 Apr 2024 09:09:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tweaklogic.com header.i=@tweaklogic.com header.b="WQwUNZ4F" Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A010653 for ; Sat, 27 Apr 2024 09:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714208994; cv=none; b=NQ0s4j3st24L+a+LeWTHeR0M0+E3MWbvgYRRbB+wdEyR4k/SBXBnXHTLNt1czYL3owMe8gH/2aGS0JUgybDCM0TxygTEojdSVE2tQSoepjDwd0zxoCFmVqD4CvVkKNbHWmkrejIjG9zizVXePRT4TavKcriqVxGs2plokuCLjcQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714208994; c=relaxed/simple; bh=E3WKdL8IOBMRfle/wo50Z1qqZX5pXztf7kFCkdRe6FI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Dn+cXCLV0uFHeHFq0BOYdsQ+AYKWd2oqBpuWxXQuqY1I5n4FasCAg2EX4DRFuK3FFJ1g437RZOdZzZkeAb1pVsq7AFBrvCXiMsn5Dygforrf/XdO0WNImP2Uv/meFElw7BLio63LRLbCpZoYrSGYnNrzYGDfDLagLeX+LoCBOPo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tweaklogic.com; spf=pass smtp.mailfrom=tweaklogic.com; dkim=pass (2048-bit key) header.d=tweaklogic.com header.i=@tweaklogic.com header.b=WQwUNZ4F; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tweaklogic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tweaklogic.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1e9451d8b71so26023845ad.0 for ; Sat, 27 Apr 2024 02:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tweaklogic.com; s=google; t=1714208990; x=1714813790; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ynRU3BokI7x+TVZ0M1ndHqpxWwtn8+UGCy+jVf6kUXE=; b=WQwUNZ4F/ICkm6UUMy6il8WxVgctzJZHUo/PTDqS65SK8vsMrbPW4m7ZmZZvIXlSfT WTuU1bJ9Ab4DXLCklwMCmRnKTF7wKpgeP/1Ezl1z5DhYsrBD4VqLko+q0i+cCKrJlXkn 7VdIbXPMuOqDezADmPjTEE4yCsw7E98ZfThxof/kUM4Dx+JhQuACyyFxeYZEomZCaE5u oEnHIKLaM6BZQOz7BAdLu93JA1eYp+3NWcQxyhW7gZTRRBuWozViN1plDIe2D5j7PUrT QoTwPTdmz3y+vpUU+G/M/KVvrg1/eIZWeugC+DSgD7c/JZkfLxyvnvs2KoerixNXr0Qt ymvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714208990; x=1714813790; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ynRU3BokI7x+TVZ0M1ndHqpxWwtn8+UGCy+jVf6kUXE=; b=aSAEDY/2uHJToNxG5gZmLfbqxFjg9RfODRnYe3tLNxCjCce1EsGKMBhEFrSfDOGKYq dT3ZEjgf2yv54aU8Zr9bNDm9TQbSRT6Tq9PaM8yBZJhPWcZ66k5mWx2Oi1f6C5qBXzND TOYn9ub2+hljXaTEiLgXQrgp6KmdNZtPeSVBH15MUEREpB97zBK0kPXjHPe94uv8P14d 3GU07Mz/mZsg8Eb3qAYdvEv3EMKyvo9zDoscuOAhLRFHBvjoyq6bqwosg5cRu1b/RqJl 6jcNcXrlPww8vB6OHF60+N95x6+Z0FHV3330enmqezZBJz3xNtpFx2FpxBKxocwnXcHO PyMw== X-Forwarded-Encrypted: i=1; AJvYcCXs0b8jSMZzmZ21R/2Tn2M9gpCKK3Z1zM0wFrvBbEOWZKs0ym5KubzIU2tf0yLHKu42idc0QZTi5J5tI+ROPy7tHXe1g+pTe9T7uNFl X-Gm-Message-State: AOJu0YzlNue7LHT6jPTAVfyaTTb2n+NPX1wC5F2mjTI7c8yADa/YPN/6 AmJJEKTtdS96zPHJqQ4S114FeNWB8UZhxFb11XsbwroSDcPaaOFvkMW18Wr/3JXub+GjfBXFkeC A X-Received: by 2002:a17:903:1212:b0:1e3:999a:9726 with SMTP id l18-20020a170903121200b001e3999a9726mr5929362plh.29.1714208990174; Sat, 27 Apr 2024 02:09:50 -0700 (PDT) Received: from localhost.localdomain ([180.150.112.31]) by smtp.gmail.com with ESMTPSA id w17-20020a1709029a9100b001e2a4663179sm16726519plp.258.2024.04.27.02.09.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Apr 2024 02:09:49 -0700 (PDT) From: Subhajit Ghosh To: Jonathan Cameron , Lars-Peter Clausen , Dan Carpenter Cc: Subhajit Ghosh , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] iio: light: apds9306: Fix input arguments to in_range() Date: Sat, 27 Apr 2024 18:39:14 +0930 Message-Id: <20240427090914.37274-1-subhajit.ghosh@tweaklogic.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Third input argument to in_range() function requires the number of values in range, not the last value in that range. Update macro for persistence and adaptive threshold to reflect number of values supported instead of the maximum values supported. Fixes: 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor") Signed-off-by: Subhajit Ghosh --- drivers/iio/light/apds9306.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c index 46c647ccd44c..d6627b3e6000 100644 --- a/drivers/iio/light/apds9306.c +++ b/drivers/iio/light/apds9306.c @@ -55,8 +55,8 @@ #define APDS9306_ALS_DATA_STAT_MASK BIT(3) #define APDS9306_ALS_THRES_VAL_MAX (BIT(20) - 1) -#define APDS9306_ALS_THRES_VAR_VAL_MAX (BIT(3) - 1) -#define APDS9306_ALS_PERSIST_VAL_MAX (BIT(4) - 1) +#define APDS9306_ALS_THRES_VAR_NUM_VALS 8 +#define APDS9306_ALS_PERSIST_NUM_VALS 16 #define APDS9306_ALS_READ_DATA_DELAY_US (20 * USEC_PER_MSEC) #define APDS9306_NUM_REPEAT_RATES 7 #define APDS9306_INT_SRC_CLEAR 0 @@ -726,7 +726,7 @@ static int apds9306_event_period_get(struct apds9306_data *data, int *val) if (ret) return ret; - if (!in_range(period, 0, APDS9306_ALS_PERSIST_VAL_MAX)) + if (!in_range(period, 0, APDS9306_ALS_PERSIST_NUM_VALS)) return -EINVAL; *val = period; @@ -738,7 +738,7 @@ static int apds9306_event_period_set(struct apds9306_data *data, int val) { struct apds9306_regfields *rf = &data->rf; - if (!in_range(val, 0, APDS9306_ALS_PERSIST_VAL_MAX)) + if (!in_range(val, 0, APDS9306_ALS_PERSIST_NUM_VALS)) return -EINVAL; return regmap_field_write(rf->int_persist_val, val); @@ -796,7 +796,7 @@ static int apds9306_event_thresh_adaptive_get(struct apds9306_data *data, int *v if (ret) return ret; - if (!in_range(thr_adpt, 0, APDS9306_ALS_THRES_VAR_VAL_MAX)) + if (!in_range(thr_adpt, 0, APDS9306_ALS_THRES_VAR_NUM_VALS)) return -EINVAL; *val = thr_adpt; @@ -808,7 +808,7 @@ static int apds9306_event_thresh_adaptive_set(struct apds9306_data *data, int va { struct apds9306_regfields *rf = &data->rf; - if (!in_range(val, 0, APDS9306_ALS_THRES_VAR_VAL_MAX)) + if (!in_range(val, 0, APDS9306_ALS_THRES_VAR_NUM_VALS)) return -EINVAL; return regmap_field_write(rf->int_thresh_var_val, val); base-commit: b80ad8e3cd2712b78b98804d1f59199680d8ed91 -- 2.34.1