From patchwork Thu Sep 6 15:10:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 146099 Delivered-To: patch@linaro.org Received: by 2002:a2e:5d9b:0:0:0:0:0 with SMTP id v27-v6csp661920lje; Thu, 6 Sep 2018 08:10:50 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdal3mdfiH0x9U7hM0c8jChMzEzvAAZrYCsyCBsWpODmqGeOBsJjBzNpAYjQ25xjE0q9mV1L X-Received: by 2002:a63:9a02:: with SMTP id o2-v6mr3202745pge.440.1536246650252; Thu, 06 Sep 2018 08:10:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536246650; cv=none; d=google.com; s=arc-20160816; b=UkwdR6FYhR5HN/8LHoDq/Zr2DjXUlp1v1z1xC/1KOdQzsWMEQBJhPTx6iiAsE4cIaE +kAjDDrZ38Ko+PYp8ui6nTYVRYSEBqnIYzJSSr4jXLGuLNZzUjinES4ff0kXy9Lbmli2 gAmQtpM4CWcMFpwXowpJtJ7+8J1g5PAGgSs7YUfyTX8lvqw9GMx/YSn+/pKaqZn2A/Dv 6ZGojfz6AJR4/FSv/7Ch98v8j+o2Wn758xNzRy4CSyPEawN5Gp77yNuLI9y+12QYardy f1x/xVcg3J0dAbnCgsmoIteuSGl1N0VYf1O1tLTtbVcJstkOvg9KpeJqV9qu4PTsO5jE ilEw== 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; bh=fhjnU4+ZvTmfaTdm83CDqrxzbefmPaEb0dOafWr317M=; b=JadOd1xnxYw7wKNdFkx7Fhovw8V+L8E5eJ9wOT1C6qLYBUyNYtpr6l5YZPL2Tb7SlA r3R0NCmu4+KQ9NXYbPlqdubvy07usOlBdpGzFcNbIrPDjiU//wpV/8W4/w6Y5vIIWK++ XSf9Z3Y5JQJopQZ1ayrldrIERbvGxaYYgLnN/8EIW8noDe+9kozN4H+CAOPXRo5xt136 IDH5x0Ioz2/xQMkp1j7YaNRzswhc0hnS/q/k5+c7Rlz7APzFlSN55vAg7nk1xP2Sm9yX wIP+a0NShIDbssMVX6Loj4HXAOGUsIvK++BRjE+CSyaco99JRxVFpfeSzN6cWeRFCR6z wuQw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3-v6si5743579pgi.338.2018.09.06.08.10.49; Thu, 06 Sep 2018 08:10:50 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730224AbeIFTqp (ORCPT + 32 others); Thu, 6 Sep 2018 15:46:45 -0400 Received: from foss.arm.com ([217.140.101.70]:47116 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730093AbeIFTqp (ORCPT ); Thu, 6 Sep 2018 15:46:45 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 564A77A9; Thu, 6 Sep 2018 08:10:47 -0700 (PDT) Received: from usa.arm.com (e107155-lin.Emea.Arm.com [10.4.12.116]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id AB2163F557; Thu, 6 Sep 2018 08:10:45 -0700 (PDT) From: Sudeep Holla To: arm@kernel.org Cc: Sudeep Holla , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ionela Voinescu , Quentin Perret , Kevin Hilman , Olof Johansson , Arnd Bergmann Subject: [PATCH v2] firmware: arm_scmi: fix divide by zero when sustained_perf_level is zero Date: Thu, 6 Sep 2018 16:10:39 +0100 Message-Id: <1536246639-7420-1-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1536165491-27813-1-git-send-email-sudeep.holla@arm.com> References: <1536165491-27813-1-git-send-email-sudeep.holla@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Firmware can provide zero as values for sustained performance level and corresponding sustained frequency in kHz in order to hide the actual frequencies and provide only abstract values. It may endup with divide by zero scenario resulting in kernel panic. Let's set the multiplication factor to one if either one or both of them (sustained_perf_level and sustained_freq) are set to zero. Fixes: a9e3fbfaa0ff ("firmware: arm_scmi: add initial support for performance protocol") Reported-by: Ionela Voinescu Signed-off-by: Sudeep Holla --- drivers/firmware/arm_scmi/perf.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) Hi ARM SoC team, Can you pick this patch directly ? Regards, Sudeep -- 2.7.4 diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c index 721e6c57beae..64342944d917 100644 --- a/drivers/firmware/arm_scmi/perf.c +++ b/drivers/firmware/arm_scmi/perf.c @@ -166,7 +166,13 @@ scmi_perf_domain_attributes_get(const struct scmi_handle *handle, u32 domain, le32_to_cpu(attr->sustained_freq_khz); dom_info->sustained_perf_level = le32_to_cpu(attr->sustained_perf_level); - dom_info->mult_factor = (dom_info->sustained_freq_khz * 1000) / + if (!dom_info->sustained_freq_khz || + !dom_info->sustained_perf_level) + /* CPUFreq converts to kHz, hence default 1000 */ + dom_info->mult_factor = 1000; + else + dom_info->mult_factor = + (dom_info->sustained_freq_khz * 1000) / dom_info->sustained_perf_level; memcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE); }