From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18A94C433DF for ; Mon, 29 Jun 2020 14:45:01 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DADD523E1F for ; Mon, 29 Jun 2020 14:45:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nCnOFd9M" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DADD523E1F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=L4u/4mcVyRga3N6oyRheKdgYw8XDFHH1zY+wN8bCucE=; b=nCnOFd9MyKQe/QDfo99hsTOPh fy1TJQwTZwG4mXiixtBisHkbkZb457TaTSkUxsUvHikla5vgO6yvt+iNkeWrzPkgwG6n8NQh53NYE oL9HF3NdT7FEwOdGFhjjK+A1yY3z36gN5NqHKo/80mpXTtliwyz1CLoD7XfS1w/FH45sOY8DHlGWU Ke5My3beejyl3H9rLmnFOPkLuo12f2qZIxb007yifwL2TJkBhzZPNZUX8zj5kQ69BFOWl9dohfhmI wZbu08dsy63+7oEywWGZvqhe/LipjyKNEFZ3ZhtIzfvIMDa/hnsLKpP/ZwJPe7MQKN1fv5dtvd33y hC7PgFYnQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpv0M-000698-7i; Mon, 29 Jun 2020 14:43:30 +0000 Received: from mail-lf1-f67.google.com ([209.85.167.67]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpv0J-00068c-TV for linux-arm-kernel@lists.infradead.org; Mon, 29 Jun 2020 14:43:28 +0000 Received: by mail-lf1-f67.google.com with SMTP id d21so9206158lfb.6 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=sRX5E7DnECYPgKH1OCmkbboGJEWDHqJLPXxbkno2Npf15+EI2xs52GYCerzqgT79W5 IcfacC0CAuZupVD1VKfh3DU5BKdXtlIQzAdGflrkvbytO2DkFfaghFqXDUEIN1gKZMEn Dsf9QWhkYnvNx+nd5Ol+IVy48ddYI+itXslpJ80V26SJXxYpo9QxIGzCC+WHN213ZNRO //NITFGTZslzvAQcj8UdabsEtMe+b+tDcg4yoPfYbKkRc6U9Uj0tNyt8Arb1GMO2JjB2 bxTMw/znW3OICrIdFnxnu6e3ASXFeSjproYw5QKCpBcrEdeQORyvXhBevF7Yfrv+G+pX ALnQ== X-Gm-Message-State: AOAM5321bSuOsKPNTCHAJez9C7mm2X4AlU4hqfeqlVNSYXSKWkeX4PUb iFPc1kF5SvEY9wfGxlQXAZo= X-Google-Smtp-Source: ABdhPJxlXL/WPQmHiWHBUnNiCTuuoYT2K4kdoHBsIw1V5XczaXf3Hns3BgilQStZ/HVmyNueCKOooQ== 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 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-Disposition: inline In-Reply-To: X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chunyan Zhang , Johan Hovold , LKML , Orson Zhai , Lee Jones , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel