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=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,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 9382EC433E0 for ; Mon, 29 Jun 2020 14:36:50 +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 5F0B723E1D for ; Mon, 29 Jun 2020 14:36:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="usVSvw4j"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c3q7wPvu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F0B723E1D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nv2p3UAFxZP5Q9WH6K3FwRMlZgHdlUH0RA8A2xgRhGU=; b=usVSvw4jSc6Dj5L/oGPuooJFb GBG0PHu8H/DZhTRX/4mNmjD/gjqbzb4yNpqd5zagubVueSTQZvVIzVFodSN5WKpjvz/2S6WEQgefx DL5P4xDXRAkKuGbzsvQ8fNEib3PWw4zvW72CYD0Ao5dArjC1lbX2nD3/g8xTg8sINXsr3zHMaFMvl oJhpC1D1psCRbbuTYYyiJA0fPPGSwxkbnBbjfbZXGK/oOVthfZnOPjNJ6fAhW311aG3U++RcxLLUW DDQz9oLTR02LJt3ohfZj7UnnDZodM3kMkwPvPF6sNhgjvNGiIT+bhq/ZYT3qUMYlfC4jx9cHJ5RSp V78uLMUNA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpusW-0004lA-HI; Mon, 29 Jun 2020 14:35:24 +0000 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpusT-0004jA-0K for linux-arm-kernel@lists.infradead.org; Mon, 29 Jun 2020 14:35:21 +0000 Received: by mail-lf1-x144.google.com with SMTP id u25so9223222lfm.1 for ; Mon, 29 Jun 2020 07:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RaTcPoUQJY1lOqOm/hLw7WScDE1kdon3oAxJjzWJBGs=; b=c3q7wPvuWmxbXEeQbOXweKx9JWUXhVEdKTI9tOiGufjlgDQVL+HCyOLJP+J74EWwaS PHpEkg184kjqjYLicQRA2S5pusbsv40d2NPwsfR/i1/sI1jcwOnFMzq8I06Ep0vk/BhQ VaBAup3tV/I2JN+YGMDkQEviOdvR/Dr0DHalr7UdlABf5RkDM2ZgB2tBmszegEkzKc3S UiMzSzA38BAqrqn2UuOd4SIRwddzJyIKCPq97MFVawrYNZ2rFzK+6bKzg/tgUkx0uY76 cdWkO4Nxxb4Fdn5afDc7s2m/Ta5XCqx4EehNzw5TbXPj2N8hGm9pfhQf1kSHxkWEBnye PG4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RaTcPoUQJY1lOqOm/hLw7WScDE1kdon3oAxJjzWJBGs=; b=k91jQqcPWzBkcmksv1JPEPMWsqVG8gWxKn4hbJC9QJfR+lry2QqvNjYxszlkwBe9bO Qd2/9iQUtGvyZ1jha8i46mzOM74qeI6zLiOJhXieHYKfdxYuv5vywyLYSTGA4RCTfBo7 SXKWs7kkIjlQdYL8wK25/ZGIfFq0k9QvxX+Tt2/SuI3JaX5SAXRHdp4IujKrV7UUujWD JZRcFiEFK+/9XRd/8e7hKF9AD2TiP33fNWsynQ+HGRcW17HLFqhdMU+g7cZtz88zu8Oh KnI0ck0JDqK5j1vH+R4ZUKm+XLgmpChOMBMdcWcL7cZL/t305GcJsnRXGek6G+R7OsFE cZ+w== X-Gm-Message-State: AOAM530dH6I1v7DGpuYiM1+dg2K+NelA4MI9+fjNKtv869P+Kri60RfJ gO0UITg89DmbG2WXLZo2tmc5kD74QxfwbF2DPoO1qw== X-Google-Smtp-Source: ABdhPJw9k6oTdppBMyT/KY2IUwKfPX6ngAt9KNp5tgyRQ/K3MrIhYF73uYTXUj1LpJ3QS0XdIxjni9cckLDUTwSJIzA= X-Received: by 2002:a05:6512:108f:: with SMTP id j15mr9276546lfg.19.1593441317711; Mon, 29 Jun 2020 07:35:17 -0700 (PDT) MIME-Version: 1.0 References: <20200629123215.1014747-1-lee.jones@linaro.org> <20200629123215.1014747-5-lee.jones@linaro.org> <20200629130644.GU3334@localhost> <20200629140137.GK177734@dell> In-Reply-To: <20200629140137.GK177734@dell> From: Baolin Wang Date: Mon, 29 Jun 2020 22:35:06 +0800 Message-ID: Subject: Re: [PATCH 4/5] mfd: sprd-sc27xx-spi: Fix divide by zero when allocating register offset/mask To: Lee Jones 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: Orson Zhai , Chunyan Zhang , Johan Hovold , linux-arm-kernel@lists.infradead.org, LKML 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: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. > > However, what I appear to have overlooked is that BIT(0 % x) is not 0, > it's 1. Yes. > > > 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. > > Heh. I wonder if/how this was tested. > > I'm going to wait to hear from the authors before attempting to fix > this again. > > Baolin, Could you please clarify this for us please? Yes, see above comments. -- Baolin Wang _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel