Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3510169ybb; Mon, 23 Mar 2020 02:25:56 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt8Eph6XH24TUQaWphkKmb3PuMlYeisbykFcrCynvkcP3Jt8tj87ngFt0IgJ0ud6rqRhP0d X-Received: by 2002:aca:b308:: with SMTP id c8mr15455066oif.131.1584955556675; Mon, 23 Mar 2020 02:25:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584955556; cv=none; d=google.com; s=arc-20160816; b=CR8Pr66DkTRwpX3qoIJpyaKApuJX2rzChsoqDZJunWaEzBAX8K8PuTNBuIPEb4olEB 17+tebGU3DX3HZwH/PkAJpcc/+8E0Zj3JJFIOVWVeBO7zZHZue3+XI/I4wgahcEfXqxJ RsokIbZIE036pJoF0FqEpyQcp7s4lQBCbpiaac70pWNpLJvKw1mCu62HLVI9la657g7/ gAyBr5Nxf7u8aqNL9VqzMY7dXP6s7nqGwJe5qsSjPdmlH8sbFuw86stgJqClXbQu5qO8 tpUTBHQCfCvadAbR8ii1c+Pa0Oz+lsUN0UUMKbxhsph22vMPKRYdf2Rofe+dMg+ToXta 8kIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=C3DogahGC9+RykrmX70/1+RE3NkN/OINb0pWKE0oiy4=; b=OAmIdGVB6PEoYSshjrji25E7NqfTmeC06GYP4SDqBANcQPJL1vypFPEU+SrL3xjNDA VWCyCeCkq2zXHiW4GniwxkNUaIOhuUdItWpLHYlx4lCUgbHft3nVpjc4B/8Fhrq7nfu1 1Jqq8EcUuTOYWehKhfh6De+USzjnqndX30C7U/92F8uyIf1fWM8P6k3U/TN/tNqGUxvg cNYcZjNILBg1YWnmkquj4H0VhVZ4faBdZ5Z5M8xQ0RItT9EUUcvwUbvl2nyankdDOebL M30id1pUU37Y7g+IvJa7C6LLVF6JzBpPKHhKzK6sd0NbMcXUyMC5Ad2AMV4bTQ1SJxR+ y8yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=KY4NTm1x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r187si594529oig.168.2020.03.23.02.25.44; Mon, 23 Mar 2020 02:25:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=KY4NTm1x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727740AbgCWJYt (ORCPT + 99 others); Mon, 23 Mar 2020 05:24:49 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:39885 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727714AbgCWJYs (ORCPT ); Mon, 23 Mar 2020 05:24:48 -0400 Received: by mail-pj1-f66.google.com with SMTP id ck23so5817599pjb.4 for ; Mon, 23 Mar 2020 02:24:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=C3DogahGC9+RykrmX70/1+RE3NkN/OINb0pWKE0oiy4=; b=KY4NTm1xU1uLWsixTz3NKCGR6EPu+Z2kNC/ShiFbEjkV+4fQIuniGYnVYTbdlyeB0U BRsww8PZH723mNWmelL0ybE4OPO5GnTtHGYMXxwKr41x9UaPBcttTER9W7dzwxYUr0Ma HByNd0+RMg8Gk/1IBidHXMtwssmwRJT4EhhT0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=C3DogahGC9+RykrmX70/1+RE3NkN/OINb0pWKE0oiy4=; b=qeGEe+ihAzLLe9Rmw4/b7JGULy16HvPfOxkkPNSyl/81KkSVZuif80+FT5mF7vT2ij EdxjbWqGs19Pc37JpQDamZFCWxsfVhBkYyb0yEciIsqR9K+kxgmK/hMnWpYBH4JMaA99 LurIjycwNuQoDzGGvqlH+cSYrbjHtX05ZZM1OHBx8KxX+cmymhWIg0iobQ7gHq0jJGfJ Xd27EDDihVDNKzhYGO5Hjs7Dl6Yd8ILnXsULiKYHlyVX6DE7QM6sF/MT+KdTsdom2Gyn EJfZnBVFyezHgedPDCcIqqolSeBjnWy7IRwk4RE46KkO3Axbr7XuMNvBcJEt65DKl7HS xINg== X-Gm-Message-State: ANhLgQ1uRJMwSka1wf9BWN4BV8HRxS8ubyZxNBJI4iJcfFrpIqsQbVwh NRBpIrudV5lOBVUPdE6g8mgSBA== X-Received: by 2002:a17:90a:9742:: with SMTP id i2mr2863545pjw.194.1584955488035; Mon, 23 Mar 2020 02:24:48 -0700 (PDT) Received: from rayagonda.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id t186sm1093068pgd.43.2020.03.23.02.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 02:24:47 -0700 (PDT) From: Rayagonda Kokatanur To: Thierry Reding , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Yendapally Reddy Dhananjaya Reddy , linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Rayagonda Kokatanur Subject: [PATCH v2 1/2] pwm: bcm-iproc: handle clk_get_rate() return Date: Mon, 23 Mar 2020 14:54:23 +0530 Message-Id: <20200323092424.22664-2-rayagonda.kokatanur@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200323092424.22664-1-rayagonda.kokatanur@broadcom.com> References: <20200323092424.22664-1-rayagonda.kokatanur@broadcom.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Handle clk_get_rate() returning <= 0 condition to avoid possible division by zero. Fixes: daa5abc41c80 ("pwm: Add support for Broadcom iProc PWM controller") Signed-off-by: Rayagonda Kokatanur --- drivers/pwm/pwm-bcm-iproc.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c index 1f829edd8ee7..8bbd2a04fead 100644 --- a/drivers/pwm/pwm-bcm-iproc.c +++ b/drivers/pwm/pwm-bcm-iproc.c @@ -99,19 +99,25 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm, else state->polarity = PWM_POLARITY_INVERSED; - value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET); - prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm); - prescale &= IPROC_PWM_PRESCALE_MAX; - - multi = NSEC_PER_SEC * (prescale + 1); - - value = readl(ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->hwpwm)); - tmp = (value & IPROC_PWM_PERIOD_MAX) * multi; - state->period = div64_u64(tmp, rate); - - value = readl(ip->base + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm)); - tmp = (value & IPROC_PWM_PERIOD_MAX) * multi; - state->duty_cycle = div64_u64(tmp, rate); + if (rate == 0) { + state->period = 0; + state->duty_cycle = 0; + } else { + value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET); + prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm); + prescale &= IPROC_PWM_PRESCALE_MAX; + + multi = NSEC_PER_SEC * (prescale + 1); + + value = readl(ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->hwpwm)); + tmp = (value & IPROC_PWM_PERIOD_MAX) * multi; + state->period = div64_u64(tmp, rate); + + value = readl(ip->base + + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm)); + tmp = (value & IPROC_PWM_PERIOD_MAX) * multi; + state->duty_cycle = div64_u64(tmp, rate); + } } static int iproc_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm, -- 2.17.1