From patchwork Wed Sep 5 16:38:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 146010 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp5159621ljw; Wed, 5 Sep 2018 09:38:24 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYJnJXc3JQd4Ylmc04NEtnLi35a+OVKeKtUCi3vBo93JDw/3DOYdPXw8chExdo93L/jRgC9 X-Received: by 2002:a62:cfc6:: with SMTP id b189-v6mr41555902pfg.224.1536165503683; Wed, 05 Sep 2018 09:38:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536165503; cv=none; d=google.com; s=arc-20160816; b=0Z/BZX40d30uBuMjWLKps6N7918VllupJdcDEvK5zne0ktL725Qctzwq07UE4Z8l2y 2nc/mTC2sTFOdJE9VlMk3xzRLmE3QBga1HRNgDdyLs0tdWrkpRe62uJSlW38OKGJ0CmT 5lWHRIl0tynKUXve8f1m643jlvbiPW53BAeEM/l9KDwW7XsWIHhSJh9BOJXNRJl2Lmk3 t2ZG5VNukpyCYv/Alill79r/Ujj28vigSO5LbjTIYO6chBSoxuC4aXtAf/iExcQAM5C8 GXmPc/hQREjlaMuPcEQZjfm5pU++Z+kPFWAkLeyRCXptgah4RX3m6ENo3EZZ1x/N5eyr tIDA== 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; bh=3GAyCexA46oEOqXHMrc14uIFh008536CkmfbkTeI7EQ=; b=FN10zCtMtVhqEAt74rxwHnhMd6KHMOnF1QsbimOZwRAJahJ4YEgjc/jOaWshLo+W9D +Woipb3MB99gMLzxGk3lHmIHFdqA6snwCC3p83fclq72nWKxeUVJmd1jhamWXSeFSXYg TUsXmYQABG000MquAuhOX7vtrGNGli+GP4dk1h+1v/9WPcgQ8L5+AExnvr5GSx8CfW/R qanTaW+flqGRc0E+BnDI93oMgMA9OwCJ9rNu9Mv5rrXZXYxHPEbuzqOpyDltnxYM7n1Q bHajR7IzwGSOH2v+WZFQRkDIkzQweYsJYvPplOTRnstG07jNDRAY8d/uRsv7NUZtRFnw HYFA== 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 i33-v6si2407853pld.306.2018.09.05.09.38.22; Wed, 05 Sep 2018 09:38:23 -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 S1727572AbeIEVJT (ORCPT + 32 others); Wed, 5 Sep 2018 17:09:19 -0400 Received: from foss.arm.com ([217.140.101.70]:32910 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbeIEVJT (ORCPT ); Wed, 5 Sep 2018 17:09:19 -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 CCD3F7A9; Wed, 5 Sep 2018 09:38:20 -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 D2F983F5BC; Wed, 5 Sep 2018 09:38:18 -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] firmware: arm_scmi: fix divide by zero when sustained_perf_level is zero Date: Wed, 5 Sep 2018 17:38:11 +0100 Message-Id: <1536165491-27813-1-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 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 | 7 ++++++- 1 file changed, 6 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..51c08394026b 100644 --- a/drivers/firmware/arm_scmi/perf.c +++ b/drivers/firmware/arm_scmi/perf.c @@ -166,7 +166,12 @@ 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) + dom_info->mult_factor = 1; + 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); }