From patchwork Sun Nov 6 15:46:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 13033487 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 7AE58C433FE for ; Sun, 6 Nov 2022 15:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbiKFPqT (ORCPT ); Sun, 6 Nov 2022 10:46:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbiKFPqS (ORCPT ); Sun, 6 Nov 2022 10:46:18 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C6C0D2E7 for ; Sun, 6 Nov 2022 07:46:17 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id b2so24375603eja.6 for ; Sun, 06 Nov 2022 07:46:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IESrdIGOIZAm+SZQoTxRhJ5XsZQ5NE5GBRmcNiJagyU=; b=F2cbbEOvg/pHLRp+l7YZGXVwAhe6m49SvHaqxvpPII2/ZU/hnCFzeTyOcT4rjzfRjC 5Sufm6GvLr1SU6ugGLBIobRlxXsGPdKq5Fo/7HTy3oThl7o0HsUnCy7zv19liqqVz/LQ tt9CiBfEZIVR/6fuKdwAXIIj3lK2g8XuAqIYI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IESrdIGOIZAm+SZQoTxRhJ5XsZQ5NE5GBRmcNiJagyU=; b=wgn8+qE+P6DUasEaCbn5e3Fmu8Bbk4bD/DDcaU5izCodiZ48/BNJwuEdWw7eeY1a0J PZ6vb62PdTmBLgwU/yx0wcfef4C9d6meZsy6JwDvDZ3jrDcYbZ2oqJYYKaKWIMKPdo0r Dd/UVn+pYA4Fm/C0JSmid8wca1zM5EnPdXCHx9MjHA0buSL16TT4DaPwEFbfn+teIbbP DrAcb8yNVDMi2dII8LTwZf+DQvsgXePPqYy9s/UgQbeIHPgiKD0QP1wrZmBX1tqVpAzw 65XnWWucSazR1nKc+S7Kxak3LBJNw+oh0M3HYwZJSXuaqs4NV912WfQ2KZQuuQR4TkzO FcFg== X-Gm-Message-State: ACrzQf1aHbY3wnS3q2hSK/YsdJKXUaOglPwCljRWGt1yxJvss9g3A3lT YXkNcAfGocfWwOckrufIYgLpKQ== X-Google-Smtp-Source: AA0mqf4NwJutTjNjlc5CwEQu295TG49ixdJix/uHZHyLRtAfyvfT3OC1G/evCQM4vJFh4EtZwHv6yQ== X-Received: by 2002:a17:906:99c1:b0:6fe:b01d:134 with SMTP id s1-20020a17090699c100b006feb01d0134mr8027170ejn.598.1667749576127; Sun, 06 Nov 2022 07:46:16 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-95-232-76-31.retail.telecomitalia.it. [95.232.76.31]) by smtp.gmail.com with ESMTPSA id kz20-20020a17090777d400b00772061034dbsm2204139ejc.182.2022.11.06.07.46.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 07:46:15 -0800 (PST) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, Amarula patchwork , Dario Binacchi , Allison Randal , Greg Kroah-Hartman , Liang He , Michael Turquette , Stephen Boyd , Tero Kristo , Thomas Gleixner , Tony Lindgren , linux-clk@vger.kernel.org, linux-omap@vger.kernel.org Subject: [PATCH v3 1/2] clk: ti: add of_ti_clk_register() helper Date: Sun, 6 Nov 2022 16:46:11 +0100 Message-Id: <20221106154612.3474940-1-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org The ti_clk_register() function is always called with the parameter of type struct device set to NULL, since the functions from which it is called always have a parameter of type struct device_node. Adding this helper will allow you to register a TI clock to the common clock framework by taking advantage of the facilities provided by the struct device_node type. Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/clk/ti/clk.c | 30 ++++++++++++++++++++++++++++++ drivers/clk/ti/clock.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/drivers/clk/ti/clk.c b/drivers/clk/ti/clk.c index 1dc2f15fb75b..e29b5c7c0dc8 100644 --- a/drivers/clk/ti/clk.c +++ b/drivers/clk/ti/clk.c @@ -560,6 +560,36 @@ int ti_clk_add_alias(struct device *dev, struct clk *clk, const char *con) return 0; } +/** + * of_ti_clk_register - register a TI clock to the common clock framework + * @node: device node for the clock + * @hw: hardware clock handle + * @con: connection ID for this clock + * + * Registers a TI clock to the common clock framework, and adds a clock + * alias for it. Returns a handle to the registered clock if successful, + * ERR_PTR value in failure. + */ +struct clk *of_ti_clk_register(struct device_node *node, struct clk_hw *hw, + const char *con) +{ + struct clk *clk; + int ret; + + ret = of_clk_hw_register(node, hw); + if (ret) + return ERR_PTR(ret); + + clk = hw->clk; + ret = ti_clk_add_alias(NULL, clk, con); + if (ret) { + clk_unregister(clk); + return ERR_PTR(ret); + } + + return clk; +} + /** * ti_clk_register - register a TI clock to the common clock framework * @dev: device for this clock diff --git a/drivers/clk/ti/clock.h b/drivers/clk/ti/clock.h index 37ab53339a9b..a75fcf775de0 100644 --- a/drivers/clk/ti/clock.h +++ b/drivers/clk/ti/clock.h @@ -199,6 +199,8 @@ extern const struct omap_clkctrl_data dm816_clkctrl_data[]; typedef void (*ti_of_clk_init_cb_t)(void *, struct device_node *); +struct clk *of_ti_clk_register(struct device_node *node, struct clk_hw *hw, + const char *con); struct clk *ti_clk_register(struct device *dev, struct clk_hw *hw, const char *con); struct clk *ti_clk_register_omap_hw(struct device *dev, struct clk_hw *hw, From patchwork Sun Nov 6 15:46:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 13033488 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 E3092C4321E for ; Sun, 6 Nov 2022 15:46:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230126AbiKFPqU (ORCPT ); Sun, 6 Nov 2022 10:46:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbiKFPqT (ORCPT ); Sun, 6 Nov 2022 10:46:19 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA19DD2E2 for ; Sun, 6 Nov 2022 07:46:18 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id s12so4493722edd.5 for ; Sun, 06 Nov 2022 07:46:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ke2ic1RycAYFmZzx9qb25pQPIAwiVR4I1nr3ghBSQyY=; b=ho8JqqapmwSd/RDkOkzpd8Jf/NHJqLUPMSZDjD/nKHvZyPLAr5SgVpldkBoqFvTwmz vHE6Nh/0pvRNYSredu41wnwnfFcib3U6Ui92jSPD+TD9uAESTgvwUL438Jo2nMAvocaI Yw/TUUtfGb3bYpOuMJLLCgHfXLiFyykCXX06s= 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:message-id:reply-to; bh=Ke2ic1RycAYFmZzx9qb25pQPIAwiVR4I1nr3ghBSQyY=; b=CF76//74AqiTMSa/6UQ9LxwaFkLPlQal1+pUymCgXfkIDAYzhGhb+PnrGi1EHeNG7i SBnwwHs3QReaEk92yPt2vshZoiBOmOxGxhZd8nrpbVnKIoHYFBJikoSD5AdMib8KHX8F WCgTvg3/tM6gNkdeAL6jfQ1GC2WvAijgy//tAJfRSKP83V90z+mjYNlqdgmBS6XZOmpl /BglfHSlP0C5B7ILakgXhqyrJmc6XS75uddKGDY3596NCmDvwwmO1gOJUyHb3V1WfD3z 9OxEWIn4+YA1sCgNf7/EOSV8a4cFsoSM9dngVEIA/5Cn3KWqx7eJmChwnvyZFZQizcYa IKyA== X-Gm-Message-State: ACrzQf1i9x1JBzvynLaHqwFaJd3vtYHuVZ0pMf7BKxHXSCkx4LPxXa4X iAa5ryu4kVSA2948QFFZ6igduA== X-Google-Smtp-Source: AMsMyM7Fojj9tQ1Vg6SAV/BahHigNrkLt1mUXfs2cA+8chM+Ve7RAbOW+voDxQ6s9lIcn9lSmPUs9w== X-Received: by 2002:a05:6402:1382:b0:464:1e50:1a41 with SMTP id b2-20020a056402138200b004641e501a41mr20978094edv.245.1667749577399; Sun, 06 Nov 2022 07:46:17 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-95-232-76-31.retail.telecomitalia.it. [95.232.76.31]) by smtp.gmail.com with ESMTPSA id kz20-20020a17090777d400b00772061034dbsm2204139ejc.182.2022.11.06.07.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 07:46:17 -0800 (PST) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, Amarula patchwork , Dario Binacchi , kernel test robot , Allison Randal , Greg Kroah-Hartman , Miaoqian Lin , Michael Turquette , Stephen Boyd , Tero Kristo , Thomas Gleixner , Tony Lindgren , linux-clk@vger.kernel.org, linux-omap@vger.kernel.org Subject: [PATCH v3 2/2] clk: ti: dra7-atl: don't allocate `parent_names' variable Date: Sun, 6 Nov 2022 16:46:12 +0100 Message-Id: <20221106154612.3474940-2-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20221106154612.3474940-1-dario.binacchi@amarulasolutions.com> References: <20221106154612.3474940-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org The `parent_names' variable was freed also in case of kzalloc() error. Instead of modifying the code to perform a proper memory release, I decided to fix the bug by not allocating memory. Since only one parent name is referenced, it is not necessary to allocate this variable at runtime and therefore you can avoid calling the kzalloc() function. This simplifies the code (even calls to kfree can be removed) and improves the performance of the routine. Signed-off-by: Dario Binacchi Reported-by: kernel test robot --- Changes in v3: - Add the "clk: ti: add of_ti_clk_register() helper" patch to the series. - Use a variable of type struct clk_parent_data to furthermore simplify the code. - Update the commit message. Changes in v2: - Fix compiling error - Add kernel test robot's Reported-by tag. drivers/clk/ti/clk-dra7-atl.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/clk/ti/clk-dra7-atl.c b/drivers/clk/ti/clk-dra7-atl.c index ff4d6a951681..373561626ec4 100644 --- a/drivers/clk/ti/clk-dra7-atl.c +++ b/drivers/clk/ti/clk-dra7-atl.c @@ -163,8 +163,8 @@ static const struct clk_ops atl_clk_ops = { static void __init of_dra7_atl_clock_setup(struct device_node *node) { struct dra7_atl_desc *clk_hw = NULL; + struct clk_parent_data pdata = { .index = 0 }; struct clk_init_data init = { NULL }; - const char **parent_names = NULL; const char *name; struct clk *clk; @@ -188,24 +188,15 @@ static void __init of_dra7_atl_clock_setup(struct device_node *node) goto cleanup; } - parent_names = kzalloc(sizeof(char *), GFP_KERNEL); - - if (!parent_names) - goto cleanup; - - parent_names[0] = of_clk_get_parent_name(node, 0); - - init.parent_names = parent_names; - - clk = ti_clk_register(NULL, &clk_hw->hw, name); + init.parent_data = &pdata; + clk = of_ti_clk_register(node, &clk_hw->hw, name); if (!IS_ERR(clk)) { of_clk_add_provider(node, of_clk_src_simple_get, clk); - kfree(parent_names); return; } + cleanup: - kfree(parent_names); kfree(clk_hw); } CLK_OF_DECLARE(dra7_atl_clock, "ti,dra7-atl-clock", of_dra7_atl_clock_setup);