Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3000776ybt; Mon, 29 Jun 2020 12:33:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8wXt047K47R8kZoNPEGfIgWMc76GerY1PTQOfRtzM9pIEErrjuAgQ6UdrBswq83r3Le0b X-Received: by 2002:a50:bb48:: with SMTP id y66mr16245438ede.147.1593459211861; Mon, 29 Jun 2020 12:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593459211; cv=none; d=google.com; s=arc-20160816; b=zum0y9P0Bsx1COhkkXghouEQHdbmBPlxBBPbfFeEEBSb/aInSejK68gdUhrzJDd832 6xNlrd+ArMIJcW/2OVcUA5DzN/C9aPEQ8Kka1e99bWLw/rPOkSX9nBHgTMMxwfdLliZH jldd+KvXXAnL86aFASBDFmsCGsUDiTzeUIdciPAAbDb04T8zMwYO0MuLOVnoD2PZMZY6 ajHrMlQbiTsR2XH31dOVttMcabeufWWnS0XI9kAsI9PssfGC8G6i9ElY6w+gNut7b2B1 8IicpMxv4jdDDbxJM+DppFd7pcXZBRjEGNw+jKkjMZMrxtD6a52nkEHC3+o1PKG2nxT2 P8+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=YSrvY7ndQQ0VwYyPuUYQZgjUMOLCrC7/BsK3Jg70uiA=; b=X4VnYhWyIZJ8s1XGVw91EhCPm2dmvsZQiaAyVALIQ3VjX8F7yZB7Jbx7/8kufpgMiZ I2ug4rBgMiBUEpqdJjDTPOjbTE/AqjSxKkG0WTfrHpo/sQA7Djr06AB0lI9UwJYZIrq0 uqM2LKaH2fSvG5TseBIwWHdMXnnXj2tFu1rTx58ZodRy+YLkuudBajJvhvFo4VSg2ZYw qs8Kkf3lPraWttk4mnVhzFhH4fHDTyVRRvnqnwHCD6a9KSqYH/16VVnfsOJV9iIE+amr TnWjJu/ccU//XowPItVadMGwjsP5u20xEVoCGzjT5V6PfHFAzteidxY8V8ozE+3qHRTA o3vw== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt4si423396ejc.34.2020.06.29.12.33.07; Mon, 29 Jun 2020 12:33:31 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733239AbgF2TdB (ORCPT + 99 others); Mon, 29 Jun 2020 15:33:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733235AbgF2Tcp (ORCPT ); Mon, 29 Jun 2020 15:32:45 -0400 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADE1DC02F002 for ; Mon, 29 Jun 2020 07:43:27 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id c11so9213409lfh.8 for ; Mon, 29 Jun 2020 07:43:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=YSrvY7ndQQ0VwYyPuUYQZgjUMOLCrC7/BsK3Jg70uiA=; b=EpQ/dIMdwCYLaRtO5Nv/wtgebffrzaIRTec6A8uPQLjJiTw/a0L6udd4vIUrBW/z2H PKCbFthfmiv7Xjf6wHm9W0BRiKErd/U9vpsYfZ67IDu3GUd40sBdcFjxzKsivxfBxVKU WB1qHSJxp7J+10CQOjX9GZu/5VL3waWRuX1AIDwExBLoLpiVMBp2GL5nRpHUcKFAhkyk tdzJO2JOH+JYflIsWbFApZv+CzvsLEhffvN/Gp1DQFiIitTPIfn0m+mew6jcbk9ot3AU zhQuNLaLtFGF7c5VWjYKEV3mhKLmtdJTdjcz9rsF8wf15Wp1rEg9R8w1FqAU3xPrfUks mvbw== X-Gm-Message-State: AOAM5328u0KiphH9u5eeKetW+I2wb03wZYoKwZ+BkhL4+2FIyTnVak+C HvlZJkJT40PWNpb7tUYU4Ok= X-Received: by 2002:ac2:518c:: with SMTP id u12mr9295373lfi.91.1593441806019; Mon, 29 Jun 2020 07:43:26 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id v19sm2858051lfi.65.2020.06.29.07.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2020 07:43:25 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1jpv0H-0005HB-DZ; Mon, 29 Jun 2020 16:43:25 +0200 Date: Mon, 29 Jun 2020 16:43:25 +0200 From: Johan Hovold To: Baolin Wang Cc: Lee Jones , Johan Hovold , Orson Zhai , LKML , linux-arm-kernel@lists.infradead.org, Chunyan Zhang Subject: Re: [PATCH 4/5] mfd: sprd-sc27xx-spi: Fix divide by zero when allocating register offset/mask Message-ID: <20200629144325.GV3334@localhost> References: <20200629123215.1014747-1-lee.jones@linaro.org> <20200629123215.1014747-5-lee.jones@linaro.org> <20200629130644.GU3334@localhost> <20200629140137.GK177734@dell> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 29, 2020 at 10:35:06PM +0800, Baolin Wang wrote: > On Mon, Jun 29, 2020 at 10:01 PM Lee Jones wrote: > > > > On Mon, 29 Jun 2020, Johan Hovold wrote: > > > > > On Mon, Jun 29, 2020 at 01:32:14PM +0100, Lee Jones wrote: > > > > Since ddata->irqs[] is already zeroed when allocated by devm_kcalloc() and > > > > dividing 0 by anything is still 0, there is no need to re-assign > > > > ddata->irqs[i].* values. Instead, it should be safe to begin at 1. > > > > > > > > This fixes the following W=1 warning: > > > > > > > > drivers/mfd/sprd-sc27xx-spi.c:255 sprd_pmic_probe() debug: sval_binop_unsigned: divide by zero > > > > > > > > Cc: Orson Zhai > > > > Cc: Baolin Wang > > > > Cc: Chunyan Zhang > > > > Signed-off-by: Lee Jones > > > > --- > > > > drivers/mfd/sprd-sc27xx-spi.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/mfd/sprd-sc27xx-spi.c b/drivers/mfd/sprd-sc27xx-spi.c > > > > index c305e941e435c..694a7d429ccff 100644 > > > > --- a/drivers/mfd/sprd-sc27xx-spi.c > > > > +++ b/drivers/mfd/sprd-sc27xx-spi.c > > > > @@ -251,7 +251,7 @@ static int sprd_pmic_probe(struct spi_device *spi) > > > > return -ENOMEM; > > > > > > > > ddata->irq_chip.irqs = ddata->irqs; > > > > - for (i = 0; i < pdata->num_irqs; i++) { > > > > + for (i = 1; i < pdata->num_irqs; i++) { > > > > ddata->irqs[i].reg_offset = i / pdata->num_irqs; > > > > ddata->irqs[i].mask = BIT(i % pdata->num_irqs); > > > > } > > > > > > This doesn't look right either. > > > > > > First, the loop is never executed if num_irqs is zero. > > > > The point of the patch is that 0 entries are never processed. So what's the problem? There's no division by zero here. And what compiler are you using, Lee? Seems broken. > > > Second, the current code looks bogus too as reg_offset is always set to > > > zero and mask to BIT(i)... > > Now the result is correct, since all PMIC irq mask bits are in one > register now, which means the reg_offset is always 0 can work well. > But I think the logics still can be improved if our PMIC irq numbers > are larger than 32 in future. The code is still bogus as pointed out above. Why do you bother to divide by num_irqs at all? And what have you guys been smoking? ;) Johan