Received: by 10.223.185.116 with SMTP id b49csp690036wrg; Tue, 20 Feb 2018 06:21:06 -0800 (PST) X-Google-Smtp-Source: AH8x226/GYFgTRl3dktS7nb0Xc64Qh6SJAVpDFEGY/vghIlVwQxWjw17QQQcICFnTzil/JXiHarL X-Received: by 2002:a17:902:7d8d:: with SMTP id a13-v6mr17546164plm.304.1519136466224; Tue, 20 Feb 2018 06:21:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519136466; cv=none; d=google.com; s=arc-20160816; b=cIA9CFllkryhTsSVGyLF2MBZWaAKVV3TN4XBJkbuVhaK3eEv7fhvhTK03N+EjrgpFu DK+rApXmoMQi252CaTdDCxvXV04oztBNOD1kyRbTg/nxa/eYM/F/0I4+f+kuP1QSHN/k 0LiGYbU1ccgv48GzUFyNPyBvxfd5+OQZR7ii2P2pTFJkxCNqHD/4aK4wSfVr+HI0I7K0 gqLz0fOn0lMcIDHVPGCEUT35NLuzjM6LySfGIk23qyhABvctj4FXDgDNhIipIWdl4iVW axVnhZSS4uM02x8zBrvEr2dd+GvEwTCACaJl83j5Y2a3rZKI03ighwFYTK1DcQ1boMIY O6cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=Kr410NT4h3lw9+QrwdQVpyx0MZpH/S5vVEOAWAIgQao=; b=d7rYuIU6O2iIdGOnqK20scwHKL2W541K54ZpfITDqbXRE5FQNWS2SVkyZr3C6wXodT 24Ojp95vReFHPPe89igBYboJ6dRKDNlYJ3XgI4kdKNFT2noyC4zvPthvojT63rmE2uUC TdxrxWYBoUxZk+WunD3wwrHpdeLB6XzAjWEnF21BdJvxGptBiDoQuTY3VtrdeC+k3Zi8 jZzyhe2j4t8WT2sCvnq3SkcOHZBqNvigoFtv8TgxieeG6KgY9zk0cZRSbRPyT1OBXomV UOUM/DdBRiRxFJtvGd2orJNhZpbF0UAdtlkNbtdk4HQOb72uP6toVjJfA8GEKcjPbc8Z 2+eg== 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 o7si7735641pgs.314.2018.02.20.06.20.51; Tue, 20 Feb 2018 06:21:06 -0800 (PST) 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 S1751765AbeBTOTm (ORCPT + 99 others); Tue, 20 Feb 2018 09:19:42 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:43542 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751370AbeBTOTj (ORCPT ); Tue, 20 Feb 2018 09:19:39 -0500 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 1516D1529; Tue, 20 Feb 2018 06:19:39 -0800 (PST) Received: from [10.1.210.88] (e110467-lin.cambridge.arm.com [10.1.210.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6CC8C3F25C; Tue, 20 Feb 2018 06:19:34 -0800 (PST) Subject: Re: [PATCH 1/8] clk: Add clk_bulk_alloc functions To: Marek Szyprowski , Maciej Purski , linux-media@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org Cc: David Airlie , Michael Turquette , Kamil Debski , Andrzej Hajda , Sylwester Nawrocki , Thibault Saunier , Joonyoung Shim , Russell King , Krzysztof Kozlowski , Javier Martinez Canillas , Kukjin Kim , Hoegeun Kwon , Bartlomiej Zolnierkiewicz , Inki Dae , Jeongtae Park , Jacek Anaszewski , Andrzej Pietrasiewicz , Mauro Carvalho Chehab , Stephen Boyd , Seung-Woo Kim , Hans Verkuil , Kyungmin Park References: <1519055046-2399-1-git-send-email-m.purski@samsung.com> <1519055046-2399-2-git-send-email-m.purski@samsung.com> From: Robin Murphy Message-ID: Date: Tue, 20 Feb 2018 14:19:32 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Marek, On 20/02/18 09:36, Marek Szyprowski wrote: > Hi Robin, > > On 2018-02-19 17:29, Robin Murphy wrote: >> Hi Maciej, >> >> On 19/02/18 15:43, Maciej Purski wrote: >>> When a driver is going to use clk_bulk_get() function, it has to >>> initialize an array of clk_bulk_data, by filling its id fields. >>> >>> Add a new function to the core, which dynamically allocates >>> clk_bulk_data array and fills its id fields. Add clk_bulk_free() >>> function, which frees the array allocated by clk_bulk_alloc() function. >>> Add a managed version of clk_bulk_alloc(). >> >> Seeing how every subsequent patch ends up with the roughly this same >> stanza: >> >>     x = devm_clk_bulk_alloc(dev, num, names); >>     if (IS_ERR(x) >>         return PTR_ERR(x); >>     ret = devm_clk_bulk_get(dev, x, num); >> >> I wonder if it might be better to simply implement: >> >>     int devm_clk_bulk_alloc_get(dev, &x, num, names) >> >> that does the whole lot in one go, and let drivers that want to do >> more fiddly things continue to open-code the allocation. >> >> But perhaps that's an abstraction too far... I'm not all that familiar >> with the lie of the land here. > > Hmmm. This patchset clearly shows, that it would be much simpler if we > get rid of clk_bulk_data structure at all and let clk_bulk_* functions > to operate on struct clk *array[]. Typically the list of clock names > is already in some kind of array (taken from driver data or statically > embedded into driver), so there is little benefit from duplicating it > in clk_bulk_data. Sadly, I missed clk_bulk_* api discussion and maybe > there are other benefits from this approach. > > If not, I suggest simplifying clk_bulk_* api by dropping clk_bulk_data > structure and switching to clock ptr array: > > int clk_bulk_get(struct device *dev, int num_clock, struct clk *clocks[], >                  const char *clk_names[]); > int clk_bulk_prepare(int num_clks, struct clk *clks[]); > int clk_bulk_enable(int num_clks, struct clk *clks[]); > ... Yes, that's certainly a possibility; if on the other hand there are desirable reasons for the encapsulation (personally, I do think it's quite neat), then maybe num_clocks should get pushed down into clk_bulk_data as well - then with dedicated alloc/free functions as proposed here it could become a simple opaque cookie as far as callers are concerned. I also haven't looked into the origins of the bulk API design, though; I've just been familiarising myself from the perspective of reviewing general clk API usage in drivers. Robin. >>> Signed-off-by: Maciej Purski >>> --- >>>   drivers/clk/clk-bulk.c   | 16 ++++++++++++ >>>   drivers/clk/clk-devres.c | 37 +++++++++++++++++++++++++--- >>>   include/linux/clk.h      | 64 >>> ++++++++++++++++++++++++++++++++++++++++++++++++ >>>   3 files changed, 113 insertions(+), 4 deletions(-) >>> >> >> [...] >>> @@ -598,6 +645,23 @@ struct clk *clk_get_sys(const char *dev_id, >>> const char *con_id); >>>     #else /* !CONFIG_HAVE_CLK */ >>>   +static inline struct clk_bulk_data *clk_bulk_alloc(int num_clks, >>> +                           const char **clk_ids) >>> +{ >>> +    return NULL; >> >> Either way, is it intentional not returning an ERR_PTR() value in this >> case? Since NULL will pass an IS_ERR() check, it seems a bit fragile >> for an allocation call to apparently succeed when the whole API is >> configured out (and I believe introducing new uses of IS_ERR_OR_NULL() >> is in general strongly discouraged.) >> >> Robin. >> >>> +} >>> + >>> +static inline struct clk_bulk_data *devm_clk_bulk_alloc(struct >>> device *dev, >>> +                            int num_clks, >>> +                            const char **clk_ids) >>> +{ >>> +    return NULL; >>> +} >>> + >>> +static inline void clk_bulk_free(struct clk_bulk_data *clks) >>> +{ >>> +} >>> + >>>   static inline struct clk *clk_get(struct device *dev, const char *id) >>>   { >>>       return NULL; >> > Best regards