Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2467527imm; Mon, 10 Sep 2018 01:25:31 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaFnSKcFlD11q4iZ8HQNwem67yVnDLDtP3uI9YvP/6/Z9v0sGA2ch87Ol/z4h2wUXK1zhjJ X-Received: by 2002:a17:902:b58a:: with SMTP id a10-v6mr20976691pls.306.1536567930796; Mon, 10 Sep 2018 01:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536567930; cv=none; d=google.com; s=arc-20160816; b=DbXKx8DgkapgE9JEVtyd/MNWH+u8qlw8FqlIciT/3uCpkWP+bj0JS+9jBv6ffBdDyr XR4Orco5qqVyxOwNnrj4mMkhddXBSnxdVLlx7GyHAjemqjLjRwaydjnt/cUGaSVuVVLq 3io2DoFYQrt0hlWvxeAz0CQERu1syOYTJZXI7DhW8BVD3DYwvnwDaCgVybjVZD4/5Mec DnWikYuZ6cQvk3huepcGH4D+cLecyPl3/wsfM1o1VVckxfVk44RLhh9IihzkkqAmy+qB Zb7paDC2+laRLg6vAU1sH4StIuqRL8awZEJ64rPg3vzRwwbuSFyNMfxKn8YkIQCdaQsT wNgA== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=XUHTNHVjI5j3bJNMMVxVP4mkTS2LsqpbpD0LpEMu8mA=; b=Rr1iANSUadx6VVBqjM48p3OFWd0zJb6p9ysKaDEYb/+e6iwFuXvqxc4CceSouX3L30 Aw0GX1GoTm+Flb26Hb2F2IUCkapJb8gBTi2xJFs6Cv3Wc5BoqhX02WLw6XGrgqZYZsfO ALL0zUUAElBixoZxCCSADFP0+MCKbQ6eA4q3LLJM1CLtCeoumNwyj+jXNjSMYIQSYVF4 xxU9ngBzZMW+P43L6GwGAos1nZA7d0toeClK5TEIy0pjjO4E17O7y3BhQf1YUSQeZIc9 /XSK+oRw+aCfbcz89JFMy0KfuKnc5Hek2ePXXMIMU2k/MXkKveau2hdyWe8QhJjnIsHM IaSw== 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 h5-v6si16915773pfd.112.2018.09.10.01.25.15; Mon, 10 Sep 2018 01:25:30 -0700 (PDT) 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 S1727754AbeIJNQ2 (ORCPT + 99 others); Mon, 10 Sep 2018 09:16:28 -0400 Received: from mail.bootlin.com ([62.4.15.54]:56232 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727658AbeIJNQ1 (ORCPT ); Mon, 10 Sep 2018 09:16:27 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id D69AE2079D; Mon, 10 Sep 2018 10:23:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (AAubervilliers-681-1-30-219.w90-88.abo.wanadoo.fr [90.88.15.219]) by mail.bootlin.com (Postfix) with ESMTPSA id 5B5BE20701; Mon, 10 Sep 2018 10:23:25 +0200 (CEST) Date: Mon, 10 Sep 2018 10:23:24 +0200 From: Boris Brezillon To: Bartosz Golaszewski Cc: Srinivas Kandagatla , "David S . Miller" , Mauro Carvalho Chehab , Greg Kroah-Hartman , Andrew Morton , Arnd Bergmann , Jonathan Corbet , Sekhar Nori , Kevin Hilman , David Lechner , Andrew Lunn , Alban Bedel , Maxime Ripard , Chen-Yu Tsai , linux-doc , Linux Kernel Mailing List , Linux ARM , Bartosz Golaszewski Subject: Re: [PATCH v2 13/16] nvmem: add support for cell lookups from machine code Message-ID: <20180910102324.52ecd8f7@bbrezillon> In-Reply-To: References: <20180907100750.14564-1-brgl@bgdev.pl> <20180907100750.14564-14-brgl@bgdev.pl> <484b6ec5-cd8e-e5c5-0c5c-2f11c504ea1c@linaro.org> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 10 Sep 2018 10:17:48 +0200 Bartosz Golaszewski wrote: > 2018-09-10 9:32 GMT+02:00 Srinivas Kandagatla : > > > > > > On 07/09/18 11:07, Bartosz Golaszewski wrote: > >> > >> From: Bartosz Golaszewski > >> > >> Add a way for machine code users to associate devices with nvmem cells. > >> > >> Signed-off-by: Bartosz Golaszewski > >> --- > >> drivers/nvmem/core.c | 143 +++++++++++++++++++++++++++------- > >> include/linux/nvmem-machine.h | 16 ++++ > >> 2 files changed, 132 insertions(+), 27 deletions(-) > >> > >> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > >> index da7a9d5beb33..9e2f9c993a07 100644 > >> --- a/drivers/nvmem/core.c > >> +++ b/drivers/nvmem/core.c > >> @@ -62,6 +62,9 @@ static DEFINE_IDA(nvmem_ida); > >> static DEFINE_MUTEX(nvmem_cell_mutex); > >> static LIST_HEAD(nvmem_cell_tables); > >> +static DEFINE_MUTEX(nvmem_lookup_mutex); > >> +static LIST_HEAD(nvmem_lookup_list); > >> + > >> static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); > >> #ifdef CONFIG_DEBUG_LOCK_ALLOC > >> @@ -285,6 +288,18 @@ static struct nvmem_device *of_nvmem_find(struct > >> device_node *nvmem_np) > >> return to_nvmem_device(d); > >> } > >> +static struct nvmem_device *nvmem_find(const char *name) > >> +{ > >> + struct device *d; > >> + > >> + d = bus_find_device_by_name(&nvmem_bus_type, NULL, name); > >> + > >> + if (!d) > >> + return NULL; > >> + > >> + return to_nvmem_device(d); > >> +} > >> + > > > > This is removed and added back in same patch, you should consider > > positioning the caller if possible to avoid any un-necessary changes. > > > >> static void nvmem_cell_drop(struct nvmem_cell *cell) > >> { > >> mutex_lock(&nvmem_mutex); > >> @@ -421,6 +436,21 @@ nvmem_find_cell_by_index(struct nvmem_device *nvmem, > >> int index) > >> return cell; > >> } > >> +static struct nvmem_cell * > >> +nvmem_cell_get_from_lookup(struct device *dev, const char *con_id) > >> +{ > >> + struct nvmem_cell *cell = ERR_PTR(-ENOENT); > >> + struct nvmem_cell_lookup *lookup; > >> + struct nvmem_device *nvmem; > >> + const char *dev_id; > >> + > >> + if (!dev) > >> + return ERR_PTR(-EINVAL); > >> + > >> + dev_id = dev_name(dev); > >> + > >> + mutex_lock(&nvmem_lookup_mutex); > >> + > >> + list_for_each_entry(lookup, &nvmem_lookup_list, node) { > >> + if ((strcmp(lookup->dev_id, dev_id) == 0) && > >> + (strcmp(lookup->con_id, con_id) == 0)) { > >> + /* This is the right entry. */ > >> + nvmem = __nvmem_device_get(NULL, > >> lookup->nvmem_name); > >> + if (!nvmem) { > >> + /* Provider may not be registered yet. */ > >> + cell = ERR_PTR(-EPROBE_DEFER); > >> + goto out; > >> + } > >> + > >> + cell = nvmem_find_cell_by_name(nvmem, > >> + lookup->cell_name); > >> + if (!cell) > >> + goto out; > > > > Here nvmem refcount has already increased, you should probably fix this! > > Indeed. > > >> > >> + } > >> + } > >> + > >> +out: > >> + mutex_unlock(&nvmem_lookup_mutex); > >> + return cell; > >> +} > > > > > > ... > > > >> diff --git a/include/linux/nvmem-machine.h b/include/linux/nvmem-machine.h > > > > > > Should be part of nvmem-consumer.h. > > > > If anything, this should probably go to nvmem-provider.h. Well, if we get rid of nvmem-machine.h, the cell-lookup stuff should go in nvmem-consumer.h not nvmem-provider.h. On the other hand, everything that is related to cell creation should be placed in nvmem-provider.h. > But I like > the gpiolib way of putting machine-specific code into a separate > header. Most systems are not interested in these definitions anyway. > IMO this is a valid use case where creating a new header makes sense.