Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1291362ybk; Thu, 21 May 2020 03:21:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTf+r0AFQx1BOGclI0+U/kFXFi5qVxz35lopWZ7QNKRtQUcqDje/4nIrjT9M7vBvpUCIli X-Received: by 2002:a50:bb07:: with SMTP id y7mr6994355ede.176.1590056519402; Thu, 21 May 2020 03:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590056519; cv=none; d=google.com; s=arc-20160816; b=bbNBpHa2m4Okl0Uj8uePAgvbmJNrokDfr5FKwEUY2wuuTZcVFCPPUnSOfBN0hWj3V0 yQTJjp/Nuuq9WyjZZhz0uw6OH/8xX4fxRntNu1sD12prf7Nj5jUtX2Zyur3HBl7BaTKG YQdFNEPlCaavQatIHUDObQFesr5AGOad/kPYBtWF2z4su82y87ezFeWk7n5Bvk6quDzo 1+kys29rzp2iLPqDhykopTWqnTWJRiMJLJuIQ+dO/6h9LX5XgyPivArq4oXBZm28rQFs uT7ESGzNzdApJ6N8rbEOFE/SYSc4dgHZ3VHqp+sZtRaETWbXLj9Mx9i6WcUUvRXpH68B zTOg== 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 :dkim-signature; bh=3soTLfyyUCy3fHQF1Qq2HbNRuRlLZGtCqlLrm7bKL0k=; b=ZNbwhgK2wOpENHw5wHWHwjBC34K/PMhl6OBUfavx8r462IPOx6sM3i72NfzbLwcRXp QsWC9d7Yqgf6340I6Shqu/cXqLn6KdihuxQTpTEOXDSouNKVj8oaEltEt0MuF2WYM0Al 9pM2MfSoO4OZab//18VxBOIke15tG0fqpDJlWrnWB9pZ2s0WYmPeChwZduwsigB/7GXX 0Re92K3FEVtO6vhV/T9qe0KGxjNk7xOut3o9dCsrf6fbuvjMWDJ1KiDJ5UL1cnlT7+vf 3dDTk2bp0Gp+pE3HbrfNje6R5nAie2GfsQR+QOrVsH50acqlm3ynZ91I9d4JpCl+cPYC djew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iLefinM5; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b18si2914191edr.76.2020.05.21.03.21.34; Thu, 21 May 2020 03:21:59 -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; dkim=pass header.i=@linaro.org header.s=google header.b=iLefinM5; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728427AbgEUKTl (ORCPT + 99 others); Thu, 21 May 2020 06:19:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726871AbgEUKTj (ORCPT ); Thu, 21 May 2020 06:19:39 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7520AC061A0F for ; Thu, 21 May 2020 03:19:38 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id i15so6082182wrx.10 for ; Thu, 21 May 2020 03:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=3soTLfyyUCy3fHQF1Qq2HbNRuRlLZGtCqlLrm7bKL0k=; b=iLefinM5WVMUYeWn89hjMmw6P3rJcMvMcXGCYe/sPgv01lWlMMB6pDIB7tTH5QdpRI J/wIHKRyTUiez45dT4rX+OBVoYtcQQpgm7r0oTowL2cwl2a8tyLfUBgdrchiF1JegdUC YA7oaI86mntloZ/obWxbf9I3aZTSG6xz1WTi4w5++XKbIBVVGmJHg9e+RQV4z1MTwZ2W qHbGdTUTZHwlOrigGy25G6d+X6N/lGlufcaLIyrCbHRV+66izSyZ+Gg08QmXz03eW6LK ysjJrOAJIR1Yhr3JDE9XVyyIQNpNUk6UhbAnuQATqftrKL4zpiKpAQXoMxry6OlhUtqY Fmfg== 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=3soTLfyyUCy3fHQF1Qq2HbNRuRlLZGtCqlLrm7bKL0k=; b=WL+o23K6vfbJ5GRueq1MRnRUmiOBWNIzkw+WnBjJkzjyK62y64cynC9CFffdWXWBU2 oUasLVuXXGpTg1hwueza1axgjHvWgfiDQnzYp1UvgSCxWI+kT1HAkOQGYwZaXSnFXTqE uiy87uXUMIXF/zknbvzoNJD7hjQ9Ph3B+xnZO5lDy6YxH8Txl9aRC8LFPVV8/O9hDqUZ NDJSRV7uRuzNAbVcxlFoFlEwrYmctMac9Q9x8fJMW80RmmSvRjRQt3b4WZRxDYtc5JBP LrvT2xjOvnAhG2tNpmH2OsVle7s4VA31aU+ieUw+oiWtxvm2ICy55hQCU0yKF5XnphRq j/YA== X-Gm-Message-State: AOAM533ra4z5xu2ft1jXIJdayKwr61tRAVwCBMCu55lDzsTQOvZ/tOuE pRwC79pMCuSyUH2Q567GA0wIzQ== X-Received: by 2002:adf:dc86:: with SMTP id r6mr7594889wrj.45.1590056377059; Thu, 21 May 2020 03:19:37 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id v126sm6842237wma.9.2020.05.21.03.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 03:19:36 -0700 (PDT) Date: Thu, 21 May 2020 11:19:34 +0100 From: Daniel Thompson To: Guru Das Srinagesh Cc: linux-pwm@vger.kernel.org, Thierry Reding , Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= , Subbaraman Narayanamurthy , David Collins , linux-kernel@vger.kernel.org, Joe Perches , Stephen Boyd , Lee Jones , Arnd Bergmann , Geert Uytterhoeven , Guenter Roeck , Dan Carpenter , linux-arm-kernel@lists.infradead.org Subject: Re: [RESEND PATCH v14 04/11] pwm: clps711x: Cast period to u32 before use as divisor Message-ID: <20200521101934.j5ivjky4e6byveut@holly.lan> References: <1d6918c3fc2976bdbdb687bf54a2ef09fc1558db.1589330178.git.gurus@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1d6918c3fc2976bdbdb687bf54a2ef09fc1558db.1589330178.git.gurus@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 20, 2020 at 03:55:57PM -0700, Guru Das Srinagesh wrote: > Since the PWM framework is switching struct pwm_args.period's datatype > to u64, prepare for this transition by typecasting it to u32. > > Also, since the dividend is still a 32-bit number, any divisor greater > than the numerator will cause the quotient to be zero, so return 0 in > that case to efficiently skip the division. > > Signed-off-by: Guru Das Srinagesh > --- > drivers/pwm/pwm-clps711x.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/pwm/pwm-clps711x.c b/drivers/pwm/pwm-clps711x.c > index 924d39a..da771b1 100644 > --- a/drivers/pwm/pwm-clps711x.c > +++ b/drivers/pwm/pwm-clps711x.c > @@ -43,7 +43,10 @@ static void clps711x_pwm_update_val(struct clps711x_chip *priv, u32 n, u32 v) > static unsigned int clps711x_get_duty(struct pwm_device *pwm, unsigned int v) > { > /* Duty cycle 0..15 max */ > - return DIV_ROUND_CLOSEST(v * 0xf, pwm->args.period); > + if (pwm->args.period > (v * 0xf)) > + return 0; This doesn't look right to me. DIV_ROUND_CLOSEST() does rounded division and the short circuit doesn't implement that. Daniel. > + > + return DIV_ROUND_CLOSEST(v * 0xf, (u32)pwm->args.period); > } > > static int clps711x_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project >