Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp463940lqh; Thu, 28 Mar 2024 07:14:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX8IHCZgZ4sgkDXjMCmrDHUzQMm0WP/CMpZ2GuEtKAnzBqGLPLulP3VCtVV3uLmKjzttF34ALeZIvk5W+cWhBt2a0yjJntFt/eRRLuDGw== X-Google-Smtp-Source: AGHT+IFc0w2nIJCb/p8FT+hI00KZrq37p0Ej7XGeI6GFmhkJpOh8WG/PV9biqk9ohii0e1/TMXq3 X-Received: by 2002:a05:6000:188a:b0:33e:beca:65ee with SMTP id a10-20020a056000188a00b0033ebeca65eemr3450444wri.2.1711635291549; Thu, 28 Mar 2024 07:14:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711635291; cv=pass; d=google.com; s=arc-20160816; b=hdxMY9eL2vBKuNrr5DD7G7lAWVwq8DpSqgsUWv1+WJByj9Zsan4UD+JNY4GrNyOqg5 4z5/HYr9bP86csI1TUGNwfVMYGABcDBGQgmftz+MvfTNFi4YlhOCKd90iH6VlHsfkxo4 VeOn2v/BmjH1K7rlOi0Ix7+JdxQFz++HwQXzM+PjJAkOjVIU6zK1bZn7LmFUo7m27oRk pAsjogDfzPPAhT1ar+m75KmJHzJbOpToq+2fU7SowvvuATefTUJvu8csdUvKkDox90NN /r4RQsBNsLOw9yLHWem/s3FSGWepdG4efgw/46cZPU2wGoNx/GznxC51TZLqwiKzyPDL WelQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6oWYRVINerjym6vzjXH/2h5b9vyRctc2Bdq5lqck3tg=; fh=tS6JtyW8CRGMUXdKdTfBHclzZvbWB8RqNuFbGOgDeUk=; b=r14fHIJJgiSSczNp7zR3mXpgYFAnakkGnGwHu0vWBGd7ep3EZELrCJRHAvqKfgvn2f ncCWJKl2sFzQq87i8XtmdRcuzRoMP8VgDN7bdodaO2hOICikrA2yxUhBgkLMrL9SmSqh LiFx6jTq0Qd8BatrzwIKHTDv6Ktg/SNtrH+T42B9BuweKYEGuK2Ym145gvg9tOWHqGtm hOUaS9TsRk1vx3VGV+PVdw8AGTuWINEzHmUK+2Kpnz2C2AklBxyyG2i0R/YJfxjK3elB cK6p9dKupcbTaAi5kFDIFQ6t8PvDCfWBfY6KOHwj5oBBURF1BVpbwfGnD72oNsuU/dWB tMEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GlV48aIO; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-123046-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123046-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u8-20020a170906068800b00a4dfd97fd17si764151ejb.831.2024.03.28.07.14.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 07:14:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123046-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GlV48aIO; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-123046-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123046-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 am.mirrors.kernel.org (Postfix) with ESMTPS id F3CB21F26F0C for ; Thu, 28 Mar 2024 14:14:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0EC257D417; Thu, 28 Mar 2024 14:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="GlV48aIO" Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 7D36F8172F for ; Thu, 28 Mar 2024 14:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711635282; cv=none; b=A3FBST7HWDCaiKWrHVHwK3Cx7Fdmw9D5K5ypN1+kFhyWFKx0eLIkxh3MbvBQRTv6JOnwAOQzhusyepjp2leapNRwZX3MdjrsgT8bWs8hspMFUFHLKeeSF8YNtS0QtFh7ROlCARkI9k6YmceZwu3gWXXiK4O2K0bR5sx+QHVwPh0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711635282; c=relaxed/simple; bh=qrYc08EP6AFDenl97miAzK1JrtIi1dnIodt4yH8JsYw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ILZdUBbXyl5vjkbIIAueevR2goU8hPfuQJBc8WgKsphLvgnWA+B2CPVKLnB85dMqrVApCugNgG7oAIcTgM16xYmCT4mKS6bIFq3WbNHcWGftKTaS96BjOU5Z3M7QbF989xI92Oxb9iEB2LEn5hviKbTWbCWNvNHvCt/1yXQoYnU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=GlV48aIO; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d700beb60bso20333621fa.1 for ; Thu, 28 Mar 2024 07:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711635277; x=1712240077; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=6oWYRVINerjym6vzjXH/2h5b9vyRctc2Bdq5lqck3tg=; b=GlV48aIOa/Kn/Ma6HdTowpp6vF92UIXaf8BA4uwQTvnXXWVhcsYA9h+2bcXKcCJ9Wi 2ywOkRv+Sv+nOw49ydAjcTYmnXBiPHHE/Q+xsDXg9Kg7AZ+Qe5cz+kAQoP233sQvPk57 LfZN4jkjMeF3qcTQJKGto0VP2uPUjr/RtGhYArbMrSNZNibqm+0V7crMpnQWXtqluxKT euBhouYNGjhy0TDDxZaIHqpiTgdtXvSnOn6f6RlvTQyXXertGjFTVhzIgCVOeqkebFo5 GBOZG2KoXEZ2sLI9acDa5srbUoBV9V687uKTifdsNPfvUS9AhNvhwWqoXmVmXMLaX5cv bmiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711635277; x=1712240077; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6oWYRVINerjym6vzjXH/2h5b9vyRctc2Bdq5lqck3tg=; b=dkLfgHTMTAqAY0RG5FRvvYGYXQmpoUsP5duhauPuhhJcN1KSxYnw3B98iTeUM7NuGM KHZe8DqdqhpcEm6j+Yvsx5B3/DN9H6APSfALFSV7ke1CzJx1n9mOzVTnt5cqP6+BbGZV IW1eXkxXQHKtaLIPbytL5vUG3BYqUnABZhQgHCY9l6N9WnJp05ihC+4wyQCUl5b+g19u xDYw6WpR2WBINNFLz0+mSBzqXXiuIKR6ARq0KzoI58LYxSsg2VWX/4yuHrif/GJiGDEr w5rsscLjvmPu7TCF+ttsEq5WB7a2O3GsqeBqlEVGaM5Szrkq1uPfF8vKt8get/JDKtpY BLHA== X-Forwarded-Encrypted: i=1; AJvYcCXEsnbOvxnsA5wK6E27H5SafWDGDRNOFaRJh/kAmzNRVQVrO9rueIt+MUfurcfszZ+XK7yPSDrRC9X6ZB6IqRzx3Eeuhqb3N0RU3S8S X-Gm-Message-State: AOJu0Yx9oDyqpVZWusEN8NGrWQc9LBOeMwX9Dks/mW5d00Vb5EABBc+x eIER5sLK5N1507hkrGdOTclDjERHQGnwMQivXtZDPWJzRrA6ZsC6km54MUtNyKM= X-Received: by 2002:a19:910f:0:b0:513:e0b8:563a with SMTP id t15-20020a19910f000000b00513e0b8563amr2582312lfd.62.1711635276475; Thu, 28 Mar 2024 07:14:36 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id w27-20020a170906131b00b00a4df7d02395sm793978ejb.86.2024.03.28.07.14.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 07:14:36 -0700 (PDT) Date: Thu, 28 Mar 2024 17:14:32 +0300 From: Dan Carpenter To: Nuno =?iso-8859-1?Q?S=E1?= Cc: Colin Ian King , Lars-Peter Clausen , Michael Hennerich , Cosmin Tanislav , Jonathan Cameron , linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] iio: addac: ad74115: remove redundant if statement Message-ID: <2b3d418d-55ee-4ca4-b6ae-bab441a76adf@moroto.mountain> References: <20240328112211.761618-1-colin.i.king@gmail.com> <3db9a68c6f71a67d95d25886fdc708de6269adc2.camel@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3db9a68c6f71a67d95d25886fdc708de6269adc2.camel@gmail.com> On Thu, Mar 28, 2024 at 02:52:43PM +0100, Nuno S? wrote: > Hi Colin, > > Thanks for your patch... > > On Thu, 2024-03-28 at 11:22 +0000, Colin Ian King wrote: > > The if statement is redundant because the variable i being > > assigned in the statement is never read afterwards. Remove it. > > > > Cleans up clang scan build warning: > > drivers/iio/addac/ad74115.c:570:3: warning: Value stored to 'i' > > is never read [deadcode.DeadStores] > > > > Signed-off-by: Colin Ian King > > --- > > ?drivers/iio/addac/ad74115.c | 3 --- > > ?1 file changed, 3 deletions(-) > > > > diff --git a/drivers/iio/addac/ad74115.c b/drivers/iio/addac/ad74115.c > > index e6bc5eb3788d..d31d4adb017e 100644 > > --- a/drivers/iio/addac/ad74115.c > > +++ b/drivers/iio/addac/ad74115.c > > @@ -566,9 +566,6 @@ static int ad74115_set_comp_debounce(struct ad74115_state *st, > > unsigned int val) > > ? if (val <= ad74115_debounce_tbl[i]) > > ? break; > > ? > > - if (i == len) > > - i = len - 1; > > - > > Hmm, this change is clearly good but I think we're actually missing the proper fix in > here. I'm being lazy and not checking the datasheet and Cosmin can further comment. > But I'm fairly sure that the intent of the code is actually to use i in the call to > regmap_update_bits(). I mean if we look at the mask AD74115_DIN_DEBOUNCE_MASK and the > possible values of val... Good eye. I haven't looked at the datasheet either, but logically I would think you go until you hit something that is too high and then step back to the valid valies. In other words the <= should be < and the i = len - 1 should just be i--. (The first element in the ad74115_debounce_tbl[] array is zero btw, so it's never going to break with i == 0). regards, dan carpenter diff --git a/drivers/iio/addac/ad74115.c b/drivers/iio/addac/ad74115.c index e6bc5eb3788d..8d484cefe5ff 100644 --- a/drivers/iio/addac/ad74115.c +++ b/drivers/iio/addac/ad74115.c @@ -559,19 +559,16 @@ static void ad74115_gpio_set(struct gpio_chip *gc, unsigned int offset, int valu static int ad74115_set_comp_debounce(struct ad74115_state *st, unsigned int val) { - unsigned int len = ARRAY_SIZE(ad74115_debounce_tbl); unsigned int i; - for (i = 0; i < len; i++) - if (val <= ad74115_debounce_tbl[i]) + for (i = 0; i < ARRAY_SIZE(ad74115_debounce_tbl); i++) + if (ad74115_debounce_tbl[i] > val) break; - - if (i == len) - i = len - 1; + i--; return regmap_update_bits(st->regmap, AD74115_DIN_CONFIG1_REG, AD74115_DIN_DEBOUNCE_MASK, - FIELD_PREP(AD74115_DIN_DEBOUNCE_MASK, val)); + FIELD_PREP(AD74115_DIN_DEBOUNCE_MASK, ad74115_debounce_tbl[i])); } static int ad74115_comp_gpio_get_direction(struct gpio_chip *chip,