Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2349009ybh; Fri, 17 Jul 2020 16:22:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4pFNTvjInlaAHUwU6+8l0UR4fLcVgdGr8jMiEr0ytaUXFWdeCBNfXtAqmOrqH4yGmLxJt X-Received: by 2002:a50:fd07:: with SMTP id i7mr11427688eds.221.1595028179146; Fri, 17 Jul 2020 16:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595028179; cv=none; d=google.com; s=arc-20160816; b=wpioxo6cASG5ogLtXnmUprmqG0J/CiCJBXYq7/I6NteXKaqy2IL+PZqfvMFh0iyoIh 9Dq04bKQ4nPEgDHUN6BwlDwoa0Y1DcsuH7n6RuAuuWiST2OOBsKRNPe6J32qubB+frwZ bsZZFVt2MCqXno7s6q8/VpgUDhjnEYhg4YqOaws8VeMvIPzPcJ/8qbzYUK58JtrV6Od/ FsiiAoaTdS7N+Y90QLgtmUxXnZxYBVu/m7KBCUTOizo4MPMh23SSw2vtGKAE+ZXJBsox 4Y1jqn6AiDCZxF5M0n4RP9q3vuD7x6NELNpDyNBQYaQi8LgOd/4Kmb4zD3tQGkL2A+Qa BCDg== 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=IVJhKu+Gp3LFHGjQOw8PatWF56LYveANRBsfi3RUZ5Q=; b=LXzIwwtVkq3zNUaPimCjODljwph5sO8sWFuUe0UX9AXEmqjp5iAnIKrKLRuzJfkCDs dj5zTvsgp/dkKPhwRogktsSUhEPT2rSff0uGqF80ycu5Hf3CkbZmaYZ0/DAb9h63bVOo Sm4JLajcBFKDB3XG1c+NDbnM/rqP4ZIjtcEJWi8OAsYFA2haCyKihW6SRO2Er4eLdFzX PvtbqPA++r99t9bag1bpidnDVqJ5Rw+qyV9qF4bV7XWfLZc7dJPY93nPPCXEAALpahv2 hiNO7lZtfo9da5LL5g9hUrO24ykhASB9LLu0/bTBJ4uRWmx1LSupb7Az0rbMAhUrc6Tg B0eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=OnhsRGNm; 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 gx2si5921947ejb.706.2020.07.17.16.22.36; Fri, 17 Jul 2020 16:22: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=@broadcom.com header.s=google header.b=OnhsRGNm; 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 S1727983AbgGQXUG (ORCPT + 99 others); Fri, 17 Jul 2020 19:20:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726556AbgGQXUF (ORCPT ); Fri, 17 Jul 2020 19:20:05 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A6DEC0619D3 for ; Fri, 17 Jul 2020 16:20:05 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id w6so12558116ejq.6 for ; Fri, 17 Jul 2020 16:20:05 -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=IVJhKu+Gp3LFHGjQOw8PatWF56LYveANRBsfi3RUZ5Q=; b=OnhsRGNmVZDhGNNrNKkJ3qUL/Z4HPDbWsDxx1SWXQzR0Adyl8HZKMHTorIIGW9B+NP GdFUuANZ60TLcSe9p19DsazMK4Ni1GrYFMOzG36v/rMXPO5xErDoodh2uKDk56EXPbOF Cu9zDXABX/VVZxE2IOk+Wllt3voMXXqKHXhXk= 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=IVJhKu+Gp3LFHGjQOw8PatWF56LYveANRBsfi3RUZ5Q=; b=dNWGOF3SiTvhu0t7hIcYkaSZ2ykVtFZcPmHOd9AWp93HAbqDHxhz9n9Jz7P169iLPW qsnnaFY9nJlohALmcM0MqdiK6hcfNPAlYCQgv8XRiIxqaI1qBy/rTXZJE/CORmaQsF5h FxW6cdNjRZFNn6KV8Q42CE9toPNDBOeRHYTQZJQvIW3rNDGpdBW6gKVV/3VMjahMikSN HBqOIQpMed9UXO7YfK+yUetIHALRKyKmq1/Cntgt1/qFOYbqFbKfBbQLynmvH31WAd7j wk9qj2uw1den4/ikbTUCX82Q+pXSo3n5gLkka2CwRPaWg49Sll8/+errgvUXRfJhVToS z/LA== X-Gm-Message-State: AOAM532IBOxrCwXSYSgv4kL+fvSOn2CTRmoHJLqugS2vm/NvIZbbC64q 1chdu5GuxLnTIv9WZR0CHYKX8A== X-Received: by 2002:a17:906:fcba:: with SMTP id qw26mr10599993ejb.112.1595028003947; Fri, 17 Jul 2020 16:20:03 -0700 (PDT) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id v11sm9074093eja.113.2020.07.17.16.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2020 16:20:03 -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 v3] pwm: bcm-iproc: handle clk_get_rate() return Date: Fri, 17 Jul 2020 16:19:54 -0700 Message-Id: <20200717231954.11695-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 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 Reviewed-off-by: Ray Jui --- Changes from v2: update commit message to remove <= condition as clk_get_rate only returns value >= 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