Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp311084rwb; Thu, 11 Aug 2022 01:47:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR5n9hhzyi75JslRL8vF8e9IGBXLL3eATKtWlxO2+125wszAq5MID8IQO3IjrpBUG27tmII0 X-Received: by 2002:aa7:d0d8:0:b0:441:4671:49d6 with SMTP id u24-20020aa7d0d8000000b00441467149d6mr10939900edo.252.1660207657415; Thu, 11 Aug 2022 01:47:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660207657; cv=none; d=google.com; s=arc-20160816; b=GXJJLe83qWh8wTBgvKEPuH0GGu28m4XtOwAc0MC+5B5brzprRk9oOJIyZLz0H5h4Du ECerUq6I3zTURbXl9EPCRLA1uLSKiXxEYBiNvGFVJOScWUKF5d28n3doy3IF9TZPF3Ls 5Em2S8NbZVO9otTGVrrj6xNDakYm5BKXf9cwjPl4Zd5C5bXyOwXJsVb/HXhpLNPY5NxN dwt6a+uXoNKryWyl7clqZ0yd626y4Q9IvF3FbQSfnUpNz6XUs8DXRMGfA0DJL95LFtPp pvlSwjsjgxOpAs3dqmAJ+NUwPpwIE+8NqpN0vPJ9NENgEm1450N+qAg3GI1I1w+Lgg/m eZGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5tIyJd7B0eaGhd67Ybtop510tDngvww4odk8IMMRG6s=; b=ZzuwCKyk2AJ73T27yGMnTRvMtskSsMRkzagSPbYb4OwHZhcLwxND2MST/gUgr8uwl2 PBfWlzdngLOggL71Mk+/SOBPOsqccdEfOUkXMMdmR1Es7C8DgRgHvyUJt/ybGsIWy9nq awaFLEZ0pAeKyLcm8krtrnpAr/e1gwnreMpkSI+AzDM/A4ky72hoXVPM8GIRMnr9J+gu SsOb1/vCuyvVr4s0rUeNTBiTRaTVP9LveNaB/ZJkD1tFI/v/NT/Lqpbz3dFgjDjpCPQM EvGLNk3uVjmJzpYpdS3k34bICTuudr6tZdq8+tC+wrepkCrkiWNeDLBJTyy8ZYv51w4l YFGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=59PQQYMw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x9-20020a170906440900b00711efd98320si6390785ejo.241.2022.08.11.01.47.11; Thu, 11 Aug 2022 01:47:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=59PQQYMw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234763AbiHKIpT (ORCPT + 99 others); Thu, 11 Aug 2022 04:45:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234683AbiHKIou (ORCPT ); Thu, 11 Aug 2022 04:44:50 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 513B891085 for ; Thu, 11 Aug 2022 01:44:44 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id z2so22093406edc.1 for ; Thu, 11 Aug 2022 01:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=5tIyJd7B0eaGhd67Ybtop510tDngvww4odk8IMMRG6s=; b=59PQQYMw0Zm5ulpJrfvpl5YbbZlB3E3YXKz3F0lHJa6V9iyaHOXFllzSGUA/WttF5q cu8gTEqEoMGsfp58/p3FdS3pDNMN5JgoWaO+ZPACoomPjbxXxxY99qb15ry/coipDDlL ysRZoptSSvNz0FpRKYueVI75Be3rKGACAhrouLBKsiAGEH5aCd6t5npSHGot1XHmPZHZ d2ZnbiE8aJodxHkc7bzA6LlFcohOuu5FyCG8nqxXzUPWxvB+FQDzBwM70Kqd/KMH6ywj KPRPEkmjiF513VWcx3dkX3fg0U+V2vtqrNS5uwzka+VdOiDUe2pooDH6oLyJkoFgrROR jdqg== 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; bh=5tIyJd7B0eaGhd67Ybtop510tDngvww4odk8IMMRG6s=; b=XnuL2shywWLo0ZOyjnnDNHP7RVwDF6HEgX1zgCljrBx2wUKtTAQOeGAXgflwj+SHGC 0GNBJtnN8NRYNQAsg8mgBalpDkP2gd0mU+ICSIdDorL3B3Gf41p4XE0r2PZcf59xxo7N 3LF+/xIwxmemmfdIn6VZ6aZe16rIJductkNLRcbYZcON7tSy6yjem6BC9gwRA7kHndPp bv6kE82OC3HKJW91Mkxg7CWCYOfIzdocIBhAKemTbB7XizbybpTFtc49jdKF+MQ0zUT4 czQbq61ifYiO6JpP19G5SO7SVsLQ0Mwp4VRQhhuz7Vds5aeJixOyYJPRpi0tjINWezDw D4Dg== X-Gm-Message-State: ACgBeo3fQupwS5Begnr41YDpU0mhgLy9Aj0fbkQxX3hPA9pqUBYNpJ/U z8jnIC65xarpMQgsfNhsCqWAEA== X-Received: by 2002:a05:6402:2398:b0:43d:fd2c:b0a2 with SMTP id j24-20020a056402239800b0043dfd2cb0a2mr30114294eda.172.1660207482897; Thu, 11 Aug 2022 01:44:42 -0700 (PDT) Received: from blmsp.fritz.box ([2001:4090:a243:8036:200c:a862:4253:884]) by smtp.gmail.com with ESMTPSA id d15-20020aa7d5cf000000b0043d6ece495asm8799314eds.55.2022.08.11.01.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Aug 2022 01:44:42 -0700 (PDT) From: Markus Schneider-Pargmann To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Matthias Brugger , Fabien Parent , AngeloGioacchino Del Regno Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann Subject: [PATCH v3 2/4] clk: mediatek: Provide mtk_devm_alloc_clk_data Date: Thu, 11 Aug 2022 10:44:31 +0200 Message-Id: <20220811084433.2598575-3-msp@baylibre.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220811084433.2598575-1-msp@baylibre.com> References: <20220811084433.2598575-1-msp@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide a helper that replaces the kzalloc with devm_kzalloc so error handling gets easier. Signed-off-by: Markus Schneider-Pargmann --- Notes: Changes in v3: - New patch drivers/clk/mediatek/clk-mtk.c | 33 ++++++++++++++++++++++++++++----- drivers/clk/mediatek/clk-mtk.h | 2 ++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index b9188000ab3c..a317e69cf298 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -18,19 +18,42 @@ #include "clk-mtk.h" #include "clk-gate.h" -struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num) +static void mtk_init_clk_data(struct clk_hw_onecell_data *clk_data, + unsigned int clk_num) { int i; + + clk_data->num = clk_num; + + for (i = 0; i < clk_num; i++) + clk_data->hws[i] = ERR_PTR(-ENOENT); +} + +struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev, + unsigned int clk_num) +{ struct clk_hw_onecell_data *clk_data; - clk_data = kzalloc(struct_size(clk_data, hws, clk_num), GFP_KERNEL); + clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, clk_num), + GFP_KERNEL); if (!clk_data) return NULL; - clk_data->num = clk_num; + mtk_init_clk_data(clk_data, clk_num); - for (i = 0; i < clk_num; i++) - clk_data->hws[i] = ERR_PTR(-ENOENT); + return clk_data; +} +EXPORT_SYMBOL_GPL(mtk_devm_alloc_clk_data); + +struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num) +{ + struct clk_hw_onecell_data *clk_data; + + clk_data = kzalloc(struct_size(clk_data, hws, clk_num), GFP_KERNEL); + if (!clk_data) + return NULL; + + mtk_init_clk_data(clk_data, clk_num); return clk_data; } diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h index adb1304d35d4..4390058d172c 100644 --- a/drivers/clk/mediatek/clk-mtk.h +++ b/drivers/clk/mediatek/clk-mtk.h @@ -182,6 +182,8 @@ void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num, struct clk_hw_onecell_data *clk_data); struct clk_hw_onecell_data *mtk_alloc_clk_data(unsigned int clk_num); +struct clk_hw_onecell_data *mtk_devm_alloc_clk_data(struct device *dev, + unsigned int clk_num); void mtk_free_clk_data(struct clk_hw_onecell_data *clk_data); struct clk_hw *mtk_clk_register_ref2usb_tx(const char *name, -- 2.36.1