From patchwork Sat Oct 1 17:10:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabien Parent X-Patchwork-Id: 611801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65E6DC43217 for ; Sat, 1 Oct 2022 17:11:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229436AbiJARLG (ORCPT ); Sat, 1 Oct 2022 13:11:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbiJARLG (ORCPT ); Sat, 1 Oct 2022 13:11:06 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B6045A2ED for ; Sat, 1 Oct 2022 10:11:04 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id u10so11071307wrq.2 for ; Sat, 01 Oct 2022 10:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=YHOQ8ywlbK0fpRlF8bymKRRxYbAe1JYFFKpNvoXmLTc=; b=PQYX1b3WPfpe0x2Fmbp2rME42Xu5jQKv6PUU6e/28nzTG072cA+2b+CrAKYB/kSUYc MelmLmb/pQco1l5kSxx7OLn1QcyeDQQmBuY24NXePgq25OO9j/iAD0K05hU/ctnJSrJ9 vPEUOEEMNU5poui0za/ihUstAYbUNYGDxabqAWKhVKKUUslr0GuYwyPv7eKxg3QZnfI9 gamj1GfvuXEsePfHhx6K8ns5zTdtaoTvovBHPXPsh2YOrDYtqkMcMkv54kCYYiL1TJi9 wAqWtXCdjum9wQu9qv9cxRsFDEzWh4yICOxQGMNnZI+deWlQ/eRfckwtNyvyK76brV+W O6UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=YHOQ8ywlbK0fpRlF8bymKRRxYbAe1JYFFKpNvoXmLTc=; b=m5uq3UYxyl0A4VQyd5oJISZMff+Wg0eKmnOjtFVs2sGPOybuc8N5CwwLcO4bM/03qu onKwH2uUolK4+DBlae6yEK/Xdq59EMXsIbKXQlcQ0aSM6mqvIJUr7xl5q8KeuWR50OeF eTLQs6YA2D82K91GMMz4NslAJC7UQAW5rZAQ1NFrrM6My/IS4MOALplnvZRZQaN08hk/ wNCnQOq57N0Z0XdB6L/nuKH0tj7g/FRbsGdgR8p6k2OElWqXDmpJG8lgcmkdx2ulUpkw 8spPnBEBmdXg9V4VJwIzZaU0BKy1txAeWD8GZVGIb6b5BkqzMvKhn9ie9ak+tJfwAMCv 4Lsw== X-Gm-Message-State: ACrzQf06ycTexbTA5elsUHi1x1vgQgjSLDoc89lWR9jByRA2f3iicBJr NwSOFBqifyScMnp7tGOFSRBP2w== X-Google-Smtp-Source: AMsMyM4Rgu7zhGQsIpV1EOpQQ3WcvL47Dq2sP16tSAWhcfuj52TzHaGFdXlgR6FATnwHIGLb636zAQ== X-Received: by 2002:a05:6000:2a7:b0:22a:f98f:b75f with SMTP id l7-20020a05600002a700b0022af98fb75fmr9443666wry.373.1664644262969; Sat, 01 Oct 2022 10:11:02 -0700 (PDT) Received: from radium.lan ([88.160.162.107]) by smtp.gmail.com with ESMTPSA id h40-20020a05600c49a800b003b49ab8ff53sm5817641wmp.8.2022.10.01.10.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 10:11:02 -0700 (PDT) From: Fabien Parent To: ilia.lin@kernel.org, agross@kernel.org, bjorn.andersson@linaro.org, rafael@kernel.org, viresh.kumar@linaro.org Cc: linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Fabien Parent Subject: [PATCH 2/3] cpufreq: qcom: pass pvs_name size along with its buffer Date: Sat, 1 Oct 2022 19:10:26 +0200 Message-Id: <20221001171027.2101923-2-fabien.parent@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221001171027.2101923-1-fabien.parent@linaro.org> References: <20221001171027.2101923-1-fabien.parent@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The get_version handler takes a pvs_name buffer and can override it with the speed, pvs, and pvs version values. The function does not take as argument the buffer size and is currently being determined by calling `sizeof("speedXX-pvsXX-vXX")`. This is not great because it duplicates the string in several locations which makes it error-prone if we need to modify the string someday. Also since the buffer and its size are tied together, it makes sense that they should both be passed together to the get_version as parameters. This commit makes sure that the PVS name template string is only defined once, and that the pvs_name buffer is passed with its size. Signed-off-by: Fabien Parent --- drivers/cpufreq/qcom-cpufreq-nvmem.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cpufreq-nvmem.c index 3bd38acde4b9..64ce077a4848 100644 --- a/drivers/cpufreq/qcom-cpufreq-nvmem.c +++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c @@ -30,6 +30,7 @@ #include #define MSM_ID_SMEM 137 +#define PVS_NAME_TEMPLATE "speedXX-pvsXX-vXX" enum _msm_id { MSM8996V3 = 0xF6ul, @@ -50,6 +51,7 @@ struct qcom_cpufreq_match_data { int (*get_version)(struct device *cpu_dev, struct nvmem_cell *speedbin_nvmem, char **pvs_name, + size_t pvs_name_size, struct qcom_cpufreq_drv *drv); const char **genpd_names; }; @@ -172,6 +174,7 @@ static enum _msm8996_version qcom_cpufreq_get_msm_id(void) static int qcom_cpufreq_kryo_name_version(struct device *cpu_dev, struct nvmem_cell *speedbin_nvmem, char **pvs_name, + size_t pvs_name_size, struct qcom_cpufreq_drv *drv) { size_t len; @@ -208,6 +211,7 @@ static int qcom_cpufreq_kryo_name_version(struct device *cpu_dev, static int qcom_cpufreq_krait_name_version(struct device *cpu_dev, struct nvmem_cell *speedbin_nvmem, char **pvs_name, + size_t pvs_name_size, struct qcom_cpufreq_drv *drv) { int speed = 0, pvs = 0, pvs_ver = 0; @@ -235,7 +239,7 @@ static int qcom_cpufreq_krait_name_version(struct device *cpu_dev, goto len_error; } - snprintf(*pvs_name, sizeof("speedXX-pvsXX-vXX"), "speed%d-pvs%d-v%d", + snprintf(*pvs_name, pvs_name_size, "speed%d-pvs%d-v%d", speed, pvs, pvs_ver); drv->versions = (1 << speed); @@ -265,7 +269,7 @@ static int qcom_cpufreq_probe(struct platform_device *pdev) struct nvmem_cell *speedbin_nvmem; struct device_node *np; struct device *cpu_dev; - char *pvs_name = "speedXX-pvsXX-vXX"; + char *pvs_name = PVS_NAME_TEMPLATE; unsigned cpu; const struct of_device_id *match; int ret; @@ -306,8 +310,8 @@ static int qcom_cpufreq_probe(struct platform_device *pdev) goto free_drv; } - ret = drv->data->get_version(cpu_dev, - speedbin_nvmem, &pvs_name, drv); + ret = drv->data->get_version(cpu_dev, speedbin_nvmem, &pvs_name, + sizeof(PVS_NAME_TEMPLATE), drv); if (ret) { nvmem_cell_put(speedbin_nvmem); goto free_drv;