From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1765068AbdAJGps (ORCPT ); Tue, 10 Jan 2017 01:45:48 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:42722 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1765048AbdAJGpp (ORCPT ); Tue, 10 Jan 2017 01:45:45 -0500 DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org 1C050613D2 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=vivek.gautam@codeaurora.org From: Vivek Gautam To: srinivas.kandagatla@linaro.org, linux-kernel@vger.kernel.org Cc: maxime.ripard@free-electrons.com, sboyd@codeaurora.org, linux-arm-msm@vger.kernel.org, Vivek Gautam Subject: [PATCH v2 2/2] nvmem: core: Allow getting nvmem cell with a NULL cell id Date: Tue, 10 Jan 2017 12:15:29 +0530 Message-Id: <1484030729-28577-2-git-send-email-vivek.gautam@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484030729-28577-1-git-send-email-vivek.gautam@codeaurora.org> References: <1484030729-28577-1-git-send-email-vivek.gautam@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The nvmem cell with a NULL cell name/id should be the one with no accompanying 'nvmem-cell-names' property, and thus will be the cell at index 0 in the device tree. So, we default to index 0 and update the cell index only when nvmem cell name id exists. Suggested-by: Stephen Boyd Signed-off-by: Vivek Gautam Reviewed-by: Stephen Boyd --- Based on torvald's master branch. This patch supersedes the earlier posted series [1] that added support to get nvmem cell by index. We don't need that patch-series. Changes since v1: - Fixed the typo s/acoompanying/accompanying. - Added 'Reviewed-by' from Stephen. [1] https://lkml.org/lkml/2016/12/23/80 drivers/nvmem/core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 5eb796acc79a..12e271f31cea 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -747,7 +747,9 @@ static struct nvmem_cell *nvmem_cell_get_from_list(const char *cell_id) * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell id * * @np: Device tree node that uses the nvmem cell. - * @name: nvmem cell name from nvmem-cell-names property. + * @name: nvmem cell name from nvmem-cell-names property, or NULL + * for the cell at index 0 (the lone cell with no accompanying + * nvmem-cell-names property). * * Return: Will be an ERR_PTR() on error or a valid pointer * to a struct nvmem_cell. The nvmem_cell will be freed by the @@ -760,9 +762,12 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, struct nvmem_cell *cell; struct nvmem_device *nvmem; const __be32 *addr; - int rval, len, index; + int rval, len; + int index = 0; - index = of_property_match_string(np, "nvmem-cell-names", name); + /* if cell name exists, find index to the name */ + if (name) + index = of_property_match_string(np, "nvmem-cell-names", name); cell_np = of_parse_phandle(np, "nvmem-cells", index); if (!cell_np) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project