Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2191066ybh; Fri, 17 Jul 2020 11:28:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymBL7vVlI5/6w0m8eKfu54xf+YT+dkFy92ryHys85gYlXXc6McyPPOLQ/4VxEsREXyhwPD X-Received: by 2002:a05:6402:228d:: with SMTP id cw13mr10598542edb.343.1595010491091; Fri, 17 Jul 2020 11:28:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595010491; cv=none; d=google.com; s=arc-20160816; b=segTYv2YoA39xneXYXDMHd5FYgr4MF1GKyBbHYzScM8KNpE1WShRJ0ZaeOnnTkkWaW qbO4B4o+gPDrnY39NWCNuU/D/JtsKq77iZQJb+TbjTSMWx2PgSZnYGst7RvWOXAzW1ec pg6HQbimHi6rNjEncvnwHG6fcluizCCYnCKH4jT2PwPCPYTtk+C3p2DEGePwL+uvxEN3 oEXXnsHOxzsKyiLAC4aIx35SuMl4yTLkcwpshd4gTAZQt7iQNJ/d8b/R++fWDoT95GhH 29qlHpdcJK+u9gheQPycT1l4Y9zuZmW9SJacnZWMtp/P9zTBhr6TUXBaIcurUL/xMQLJ RmVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=gfp8TD0TK5ywr5xVIQqXt4UYUBwsLiLq5aLmh/fWgMc=; b=fzipdrzkLqf6dOfQiPke4IGFAlZQFihMJmqKp35UclKFhiwXTR+aT8lmlvkwpyg8EO ydhqHps5s21vRTIXV/auYUObjDc0F4tMl7d3qSmhN2eWrBRDSyuetCOycRhhdzZyvsq2 ZuwlvQkJmNVY9Pd5BVuA4EvSKh+tauUDeOzpg0ag1iDdtgQTd9XEyyRZg1HwY92MDyAq QyTjxm8NQ7WMLW5d0E8ZYjDXjeuPYFW2v31vh8xQUqbZBFq/ni1e6tNoigJAFjvXWyjq v4kQ24VX12Tkk0Ogqn+AeZRQwPSxgQifjX0k40+SkSmD1NMKXcua0O09mnGy4KrtwCNt HF9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=NpK8ZB0b; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw24si5367077edb.177.2020.07.17.11.27.48; Fri, 17 Jul 2020 11:28:11 -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=@broadcom.com header.s=google header.b=NpK8ZB0b; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728066AbgGQSZ2 (ORCPT + 99 others); Fri, 17 Jul 2020 14:25:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726104AbgGQSZ1 (ORCPT ); Fri, 17 Jul 2020 14:25:27 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C99A9C0619D2 for ; Fri, 17 Jul 2020 11:25:27 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id m22so7054864pgv.9 for ; Fri, 17 Jul 2020 11:25:27 -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; bh=gfp8TD0TK5ywr5xVIQqXt4UYUBwsLiLq5aLmh/fWgMc=; b=NpK8ZB0bdMbxWzl/pq5VT8a0z5qKaNdaPRH3iPx1izQuG7KZYGuCrOn0OChRrsqiBj NkTGh1GSEJ6LAqS6Kc82gI4caz6SMeMYuVQ8L9dOG5PC13mv2aKQCsu8jcR57u5f2VS/ xm6sLguFQeBqRolXBBSzNxA/YEcTdC6Qv9iUc= 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; bh=gfp8TD0TK5ywr5xVIQqXt4UYUBwsLiLq5aLmh/fWgMc=; b=R4FkrwHJxP0WhnwqN+RnurtZDAEQgaLGu6wloYiDzJophzZSBI5sUcn2AUY/KISnH5 azKSqA8t6rg4mi3KrIefj/At8zsveBMqwabWZX/5Fo5NLqJgFlXspSvND/IO6HUcg7mC Tx4zFygYE5B2NWumBaUyEZXVsDVPW7SWpGPqFG6cfoUFsjmhvLdWsqunTvgnU6yxR7bh JJjYWeRnZV3DDF7oWnuwzRtLGszkDB9jUc0Vt1zCK+6QKNoS9cJHa7TfECZNJCk1rlFE Qd4Hst6+jcVJZJgDnAnx4UtQVJVgiTQsK3RkaKlBbcjngarv9IU0feBVcXhfpTI7yAvE a5Fg== X-Gm-Message-State: AOAM5316MqTu6iKs92D1oIAeLZxcSyJlNiV8eFvFbzZWGP8CIuEla48v WjzK/TK1bMd2U4phkNvGTDnEoA== X-Received: by 2002:aa7:9e0e:: with SMTP id y14mr8590826pfq.77.1595010327276; Fri, 17 Jul 2020 11:25:27 -0700 (PDT) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id x8sm8374708pfn.61.2020.07.17.11.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2020 11:25:26 -0700 (PDT) From: Scott Branden To: Thierry Reding , Lee Jones Cc: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , BCM Kernel Feedback , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Rayagonda Kokatanur , Scott Branden Subject: [PATCH v2] pwm: bcm-iproc: handle clk_get_rate() return Date: Fri, 17 Jul 2020 11:25:12 -0700 Message-Id: <20200717182512.26001-1-scott.branden@broadcom.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rayagonda Kokatanur 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 Signed-off-by: Scott Branden --- Changes from v1: ensure 'polarity' and 'enabled' are populated when clk_get_rate is 0. --- drivers/pwm/pwm-bcm-iproc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/pwm-bcm-iproc.c b/drivers/pwm/pwm-bcm-iproc.c index 1f829edd8ee7..d392a828fc49 100644 --- a/drivers/pwm/pwm-bcm-iproc.c +++ b/drivers/pwm/pwm-bcm-iproc.c @@ -85,8 +85,6 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm, u64 tmp, multi, rate; u32 value, prescale; - rate = clk_get_rate(ip->clk); - value = readl(ip->base + IPROC_PWM_CTRL_OFFSET); if (value & BIT(IPROC_PWM_CTRL_EN_SHIFT(pwm->hwpwm))) @@ -99,6 +97,13 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm, else state->polarity = PWM_POLARITY_INVERSED; + rate = clk_get_rate(ip->clk); + if (rate == 0) { + state->period = 0; + state->duty_cycle = 0; + return; + } + value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET); prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm); prescale &= IPROC_PWM_PRESCALE_MAX; -- 2.17.1