Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8098886ybn; Tue, 1 Oct 2019 03:13:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpdg+E80yauKps1xsW0JzjD+thRDZjasZtCGp3EgQqk1DkxQKqy03VxBIUldemigJbcR9D X-Received: by 2002:a17:906:5382:: with SMTP id g2mr12916960ejo.203.1569924807225; Tue, 01 Oct 2019 03:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569924807; cv=none; d=google.com; s=arc-20160816; b=FGh31guUmghDpTk29AJZPPYBgKGiu8NkDuw8C/BpKDJwYiS/zbretYEp0G5HX+Pc4t yBym0ex6SVu2pCH3FV2AtBsClvGQf2ic+3i3KiLoDcpfH84f7TCiewZl3HTa+seu/LqE u22uYd3bXboaFhKqyujSrwAQBHfVPRyCtMCWEUdenwQBG+ch1CN0nGxuXVBrIELIdUq4 DyrAyrAEmnXWTdWLSZNfFeKdV8DkjOQgT2jvQzouaj86rsIfVJgccKZWorXSSD47Xrho tRVvXyflLv9g3VrKOAlrb5SsR2kFnQljUqjhKh9ZFAM3kuoRmXOQVqGWFR66FmfBXTRh 21mw== 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:to:subject:dkim-signature; bh=8hy45pyP7kv6EXfVxQmzNrFK2VbFBW1Lka/Gmb0X5J0=; b=p/XKgFyIodBrbK/7F18KVytlC55g1Y4BAhbLSOGp7nv37P+rf/5449s/sQIHr99vts qY/RdZqsFU0KDVGhKBBbsaFeNuz2+4/BHF7XyN00a+1nFzi+1sE8w9Ea4ZoDgPCY36mR PQOPiWiJimCjWt+00TOfiSqszK6kK7K2vQshTdH5wm4nE3JRXnvzukoa3/0R0xIk9su3 YUXd7LFsqLngzESGdTWNZepPv0gMZPvfUySsE1dVMl7CWYNErYuoks3gaa/rZ1QvitAQ K1b3+0gAW/36IWOgomwAFgtZUBJIxp64UmXeMzQCUmPLUTX02XPKwM2nQgIdfXurNvDv RZkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J7AYTjPq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 29si9004687eje.235.2019.10.01.03.13.02; Tue, 01 Oct 2019 03:13:27 -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; dkim=pass header.i=@linaro.org header.s=google header.b=J7AYTjPq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730372AbfJAKME (ORCPT + 99 others); Tue, 1 Oct 2019 06:12:04 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54375 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730328AbfJAKMD (ORCPT ); Tue, 1 Oct 2019 06:12:03 -0400 Received: by mail-wm1-f68.google.com with SMTP id p7so2658574wmp.4 for ; Tue, 01 Oct 2019 03:12:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=8hy45pyP7kv6EXfVxQmzNrFK2VbFBW1Lka/Gmb0X5J0=; b=J7AYTjPqD5jXOPq7aic9RA8CQUOWh4TzXM79Ki6WY5pV+NU0lcnsopzWRK734enmtS aIN8K2zIIsNuDNokBRn5ANOCSDxrJASgmDumtnQiAFlKDHCYPR9QLokvRL1+7pI+r5eG EgGd8Zbkw0NIMKrY90aFXTCqcOLlhj0wWeSYELbaGGKRRS1HeVoTBbyueR2JdfkEsQ8r 6x2jjpafrgoFux01vRuGQqxDlqebtdUR0AK8nda/osYxrW+JA9rma3mZbCbek0UG6lT1 jg0Gi4EF4iTC25c+QTBfhRILf7Zc2pdnFte2FmXGPfpyRrxO8+pWrfYewQD8hrKfCeH9 f29w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8hy45pyP7kv6EXfVxQmzNrFK2VbFBW1Lka/Gmb0X5J0=; b=A2H4Nsgdi4zm69LHHgetJbY7+rnj2oucjAMI1nz5wpjeJoJOCLK7P7+JfznoXlW55h phJC83bJz2t2RREzNRSlxGJRvT5YogF80Wo/4nGfyTSMtx9lOXTqE8bC1ZPcr/Cpkg2i dzYar9QaMdqP50b0FL4tNeqz4CwS21tmA4GAfBUc8/8GBDY6cExmuSMnzvg5h4i9KTEG DYS66z0UGxMhPzCHsYwNB11Kt0tNIeIqKnh3claFmuZcPmnpnERNCTTmdJbJpHcaa017 wg2CHZpIoV17kHm7sGJcxU2jroXQExK9rDZG/DrN5qbRB34QB6if7W85fRFdXtxAQSDG 2rzQ== X-Gm-Message-State: APjAAAWMWeZh20HAoDbDp8h3Cv/rJ8htyyy+zbNXKRPkaUdVSImeDl5y Naw1QKLXwI3dDg+bfBevoPUOfA== X-Received: by 2002:a7b:cf12:: with SMTP id l18mr3198121wmg.25.1569924720081; Tue, 01 Oct 2019 03:12:00 -0700 (PDT) Received: from [192.168.86.34] (cpc89974-aztw32-2-0-cust43.18-1.cable.virginm.net. [86.30.250.44]) by smtp.googlemail.com with ESMTPSA id r2sm4155309wma.1.2019.10.01.03.11.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Oct 2019 03:11:59 -0700 (PDT) Subject: Re: [PATCH v6 1/4] nvmem: core: add nvmem_device_find To: Thomas Bogendoerfer , Jonathan Corbet , Ralf Baechle , Paul Burton , James Hogan , Lee Jones , "David S. Miller" , Alessandro Zummo , Alexandre Belloni , Greg Kroah-Hartman , Jiri Slaby , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, netdev@vger.kernel.org, linux-rtc@vger.kernel.org, linux-serial@vger.kernel.org References: <20190923114636.6748-1-tbogendoerfer@suse.de> <20190923114636.6748-2-tbogendoerfer@suse.de> From: Srinivas Kandagatla Message-ID: Date: Tue, 1 Oct 2019 11:11:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190923114636.6748-2-tbogendoerfer@suse.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/09/2019 12:46, Thomas Bogendoerfer wrote: > nvmem_device_find provides a way to search for nvmem devices with > the help of a match function simlair to bus_find_device. > > Signed-off-by: Thomas Bogendoerfer > --- Thanks for the patch, This patch looks good for me. Do you know which tree is going to pick this series up? I can either apply this patch to nvmem tree or here is my Ack for this patch to take it via other trees. Reviewed-by: Srinivas Kandagatla Acked-by: Srinivas Kandagatla --srini > Documentation/driver-api/nvmem.rst | 2 ++ > drivers/nvmem/core.c | 61 +++++++++++++++++--------------------- > include/linux/nvmem-consumer.h | 9 ++++++ > 3 files changed, 38 insertions(+), 34 deletions(-) > > diff --git a/Documentation/driver-api/nvmem.rst b/Documentation/driver-api/nvmem.rst > index d9d958d5c824..287e86819640 100644 > --- a/Documentation/driver-api/nvmem.rst > +++ b/Documentation/driver-api/nvmem.rst > @@ -129,6 +129,8 @@ To facilitate such consumers NVMEM framework provides below apis:: > struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); > struct nvmem_device *devm_nvmem_device_get(struct device *dev, > const char *name); > + struct nvmem_device *nvmem_device_find(void *data, > + int (*match)(struct device *dev, const void *data)); > void nvmem_device_put(struct nvmem_device *nvmem); > int nvmem_device_read(struct nvmem_device *nvmem, unsigned int offset, > size_t bytes, void *buf); > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > index 057d1ff87d5d..9f1ee9c766ec 100644 > --- a/drivers/nvmem/core.c > +++ b/drivers/nvmem/core.c > @@ -76,33 +76,6 @@ static struct bus_type nvmem_bus_type = { > .name = "nvmem", > }; > > -static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) > -{ > - struct device *d; > - > - if (!nvmem_np) > - return NULL; > - > - d = bus_find_device_by_of_node(&nvmem_bus_type, nvmem_np); > - > - if (!d) > - return NULL; > - > - 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); > -} > - > static void nvmem_cell_drop(struct nvmem_cell *cell) > { > blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_REMOVE, cell); > @@ -532,13 +505,16 @@ int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem) > } > EXPORT_SYMBOL(devm_nvmem_unregister); > > -static struct nvmem_device *__nvmem_device_get(struct device_node *np, > - const char *nvmem_name) > +static struct nvmem_device *__nvmem_device_get(void *data, > + int (*match)(struct device *dev, const void *data)) > { > struct nvmem_device *nvmem = NULL; > + struct device *dev; > > mutex_lock(&nvmem_mutex); > - nvmem = np ? of_nvmem_find(np) : nvmem_find(nvmem_name); > + dev = bus_find_device(&nvmem_bus_type, NULL, data, match); > + if (dev) > + nvmem = to_nvmem_device(dev); > mutex_unlock(&nvmem_mutex); > if (!nvmem) > return ERR_PTR(-EPROBE_DEFER); > @@ -587,7 +563,7 @@ struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id) > if (!nvmem_np) > return ERR_PTR(-ENOENT); > > - return __nvmem_device_get(nvmem_np, NULL); > + return __nvmem_device_get(nvmem_np, device_match_of_node); > } > EXPORT_SYMBOL_GPL(of_nvmem_device_get); > #endif > @@ -613,10 +589,26 @@ struct nvmem_device *nvmem_device_get(struct device *dev, const char *dev_name) > > } > > - return __nvmem_device_get(NULL, dev_name); > + return __nvmem_device_get((void *)dev_name, device_match_name); > } > EXPORT_SYMBOL_GPL(nvmem_device_get); > > +/** > + * nvmem_device_find() - Find nvmem device with matching function > + * > + * @data: Data to pass to match function > + * @match: Callback function to check device > + * > + * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_device > + * on success. > + */ > +struct nvmem_device *nvmem_device_find(void *data, > + int (*match)(struct device *dev, const void *data)) > +{ > + return __nvmem_device_get(data, match); > +} > +EXPORT_SYMBOL_GPL(nvmem_device_find); > + > static int devm_nvmem_device_match(struct device *dev, void *res, void *data) > { > struct nvmem_device **nvmem = res; > @@ -710,7 +702,8 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id) > 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); > + nvmem = __nvmem_device_get((void *)lookup->nvmem_name, > + device_match_name); > if (IS_ERR(nvmem)) { > /* Provider may not be registered yet. */ > cell = ERR_CAST(nvmem); > @@ -780,7 +773,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) > if (!nvmem_np) > return ERR_PTR(-EINVAL); > > - nvmem = __nvmem_device_get(nvmem_np, NULL); > + nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); > of_node_put(nvmem_np); > if (IS_ERR(nvmem)) > return ERR_CAST(nvmem); > diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h > index 8f8be5b00060..02dc4aa992b2 100644 > --- a/include/linux/nvmem-consumer.h > +++ b/include/linux/nvmem-consumer.h > @@ -89,6 +89,9 @@ void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, > int nvmem_register_notifier(struct notifier_block *nb); > int nvmem_unregister_notifier(struct notifier_block *nb); > > +struct nvmem_device *nvmem_device_find(void *data, > + int (*match)(struct device *dev, const void *data)); > + > #else > > static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, > @@ -204,6 +207,12 @@ static inline int nvmem_unregister_notifier(struct notifier_block *nb) > return -EOPNOTSUPP; > } > > +static inline struct nvmem_device *nvmem_device_find(void *data, > + int (*match)(struct device *dev, const void *data)) > +{ > + return NULL; > +} > + > #endif /* CONFIG_NVMEM */ > > #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) >