From patchwork Tue Apr 26 09:49:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 566010 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp3430576map; Tue, 26 Apr 2022 02:49:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZx+L4MdYVdacZqXxwabRaW9mny2txKan34ALhkXKrFada44ilhPGRJILJDVxhga+XJmDj X-Received: by 2002:a17:907:7b9e:b0:6f3:b5c0:b1c0 with SMTP id ne30-20020a1709077b9e00b006f3b5c0b1c0mr1415935ejc.291.1650966592383; Tue, 26 Apr 2022 02:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650966592; cv=none; d=google.com; s=arc-20160816; b=tAvHs2TtCwVLJxZ/C++6XYEiwtS+pbZEcsv5drn22CcJdsM5mOSVDimTA3126DrCc8 MRM44oC+E4iKq/0zm0OBd1ts5r2v/fTJMlTyDNZIXj9ycZTq76yboB1ltAizhmd2P0yb FiIa2IhT0iR32aB5UgiPAOCXL+ZE2qa8vxwCS9UtBlDmuJ5+8BINsobwV8oTV+AVRCfs jY5bnUYYxf0sJTnIfuZoIjuCrmzoXM7rXa8DT/bAbK6Ktu0DeJnaQQMDsuMyBbCy2124 HHAfWtUd6GcmlVToEIOhIRzEx3cVjniufgjjNslzqUEc8H26D1WWM3CbHgt7/XshQ9VS TuiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=JJrGcuChrwN2wajLdVHOdY/mEgo07TNY+NhXL/5yWtA=; b=XYILKQdhkQ0x3NCXQQbuNFaSeSq0HOPI1miLkSteQAPCFDvk4MNMJCqXT54g4qbLNP sIxBHWwqohfjSUIjQa674AUDnuzF3l5WMAkkWiUCrruYPdkd2/4Uc5jMKDZpHQVvIZB0 aBBRRtD7d4Y3Ky7zT+4G9YJ9xcZ4filv1mXg3G4YM7jrC53cJagAa5I0WnvGbhf/G/mJ CmxAsdsMzOGBKrxDNkwhxnTosZoM4CDBv8hgU6nFFqDKp61/z0XoneTcI+foiJLRHg07 W3jJ8EwG77/B+2sqqW+pdweJj0hEs/3d9/mMiSiUQhFGqTJnNF7txid+4QCiITtFPTeC zAHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JwoKldNZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id nd37-20020a17090762a500b006f01fd542c2si16084662ejc.606.2022.04.26.02.49.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 02:49:52 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JwoKldNZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 654E083A34; Tue, 26 Apr 2022 11:49:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="JwoKldNZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1F7DA8399B; Tue, 26 Apr 2022 11:49:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5176E83A6B for ; Tue, 26 Apr 2022 11:49:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=etienne.carriere@linaro.org Received: by mail-wr1-x433.google.com with SMTP id s21so9944486wrb.8 for ; Tue, 26 Apr 2022 02:49:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=JJrGcuChrwN2wajLdVHOdY/mEgo07TNY+NhXL/5yWtA=; b=JwoKldNZIDHWWMVvhYXEW2MlXS7/y1r+gFd2CtTq9xOki6d9K0e5wZuSLElxD3PBan GHPfv8vc8WEmfdDfkSznsQK3QEOPZTHf+JkfWrxvq3JvZfsoqUKWTYVCeRiVnLysKyuF cYAtrU9yMbcFaQl1b1o/u3mNOO9djMJ9ceDzTm6fwGSvWFvS7IaA0ybDHcMBllVFw3of 2FFu9BrOMld2C1eAGBRnlr93tOuqEfpeSRtQZYNzbLVQkWu0l6bYxxruBWubBGC9W3Cm PvxCktTUMB/X0vQezKCDdOU9bgJlcfCbtWViVTAcjGl97cKkN3PUoUNXbuS85h3unquZ I//A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JJrGcuChrwN2wajLdVHOdY/mEgo07TNY+NhXL/5yWtA=; b=UawBoW5Mg257eU30QZDaAdxjkdmF6Uqpp8UFVtGfmZ8KPvX6rCiuU3A/eqhkgzgAnQ 44M/9zBqI5smY68tuylWiiowU4HdNEt/V8TRF9/weqtgwPd5oXD+y4eQ2wXVzGlcZUQO 6QAB3X8F9TQvq3IFV664Hqc6P82y7xgHs1JjniEOzDjjHi9obygWecKA0BoGGKosINOE UKuoJqX69ucGniiRXglxit9SU1Dzv/x1Vl5K3e8XarVlaUr4UkXtb0XmECUPazqcQsPs sRUFPUULKAPWRtcLST0RRSU4HIGBfkeElmJET8/MH1j1FYQlfwcmJrVHAP5qtIRKFSpD SReg== X-Gm-Message-State: AOAM530C7dfoL28dELX/Rso0PClUWU8QNfpnsacIJIOEiJkzt+3ihgQD IysWa5Yiz0pAxNMrqq/YF5aqx+jomLQkaQ== X-Received: by 2002:a05:6000:1f88:b0:20a:d44b:a with SMTP id bw8-20020a0560001f8800b0020ad44b000amr11714078wrb.521.1650966582477; Tue, 26 Apr 2022 02:49:42 -0700 (PDT) Received: from lmecxl0524.lme.st.com ([2a04:cec0:10a4:d1:b81d:eca1:1a27:59be]) by smtp.gmail.com with ESMTPSA id 10-20020a5d47aa000000b0020a8b965b3dsm12905422wrb.14.2022.04.26.02.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 02:49:41 -0700 (PDT) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Lukasz Majewski , Sean Anderson , Patrick Delaunay , Gabriel Fernandez , Etienne Carriere Subject: [PATCH v3] clk: scmi: fix invalid clock name references Date: Tue, 26 Apr 2022 11:49:38 +0200 Message-Id: <20220426094938.21320-1-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Fixes clock name references in scmi_clk driver. SCMI clock names are retrieved from the SCMI firmware by invoking SCMI commands using the stack for SCMI response message hence clocks names located in the stack must be duplicated before being registered in the clock framework. Fixes: 7c33f78983c3 ("clk: scmi: register scmi clocks with CCF") Reported-by: scan-admin@coverity.com Signed-off-by: Etienne Carriere --- Changes since v2: - Remove duplicated allocation of SCMI clock names. Changes since v1: - Fix buggy test on strdup() return value --- drivers/clk/clk_scmi.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c index 57022685e2..aa339f6af2 100644 --- a/drivers/clk/clk_scmi.c +++ b/drivers/clk/clk_scmi.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Copyright (C) 2019-2020 Linaro Limited + * Copyright (C) 2019-2022 Linaro Limited */ #define LOG_CATEGORY UCLASS_CLK @@ -12,6 +12,7 @@ #include #include #include +#include static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks) { @@ -53,7 +54,9 @@ static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name) if (ret) return ret; - *name = out.clock_name; + *name = strdup(out.clock_name); + if (!*name) + return -ENOMEM; return 0; } @@ -152,21 +155,20 @@ static int scmi_clk_probe(struct udevice *dev) return ret; for (i = 0; i < num_clocks; i++) { + /* Clock name is allocated from scmi_clk_get_attibute() */ char *name; if (!scmi_clk_get_attibute(dev, i, &name)) { - char *clock_name = strdup(name); - clk = kzalloc(sizeof(*clk), GFP_KERNEL); - if (!clk || !clock_name) + if (!clk) ret = -ENOMEM; else ret = clk_register(clk, dev->driver->name, - clock_name, dev->name); + name, dev->name); if (ret) { free(clk); - free(clock_name); + free(name); return ret; }