Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2850174imu; Sun, 6 Jan 2019 11:31:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN4Z/ZwU78AfP5Hm73zpt3Ok5fqgbHgaTOGqxQbu1qYC8icOE1Z87NNRBObpewTGg48JB769 X-Received: by 2002:a63:d547:: with SMTP id v7mr8418258pgi.339.1546803083953; Sun, 06 Jan 2019 11:31:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546803083; cv=none; d=google.com; s=arc-20160816; b=QTMzsnIBQaAaxllA8k9H6sdnKqo7umaiLTcilh0ZWYOM99W9+ppggHbTZqAIpherr0 Sfagc3shnRsPTD4UKVvbQZq7HwSQDgRhjk7gwxlVLN+j31Bn/JCwkN26GyN/HJ8DJIqc b3cI2DQBcw2ItZVc7x8CcuFR1YFzYgg2xCk3iyAvuVAq5YwxdejTWhqP2774BX0QxYI7 HIRg20+BWRKWdDEsKNtzXXkcckhUhTmEksO0V2ihRmol3/s+HCQTsyMQT68mmaVPcwx1 n8+h4IDvM0cG5t3qHSW9DjtlW4/IiOKjv829O0t3gNxrCynWYvjV8UKq5ZViGjhZWJn5 9jgQ== 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:date:subject:cc:to:from; bh=9Q4jAnRq8kV3MsV3ScYfm4AErZLyGo0/UWW7bZk3rzM=; b=oQnmmhdtbvWYXD+y+NW4zeeSEgzsdwjF2tPHX5CLkQxNRSOD1db2Ug/szIRReEmzLC 1mYXXSQO6mgQmDjUecDnC4xu7NbhSLksNNj9cA+2Q4nLuxkuVkufZ8G8Hj3PYjjQIH1l ZkdD2tjbpWVeJZXok/zBTHq3hoc15XHdkyoh6PpMUotGYf0ffjmR/Otucp1k+IOOrGSb QwLKbRb4cDZJUP+wlJu4xV3vUVDe97zWwxl7uIvthV0om9ybXvCl0z3a8uN7jlzy+rSe h/6yqaS9uokktetkcyrmvSrDUHYqjB1h9r65RIp7F9XnoC6mf6F/YaBpa3eL8UsCH7Fa jPhA== 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 k134si60046848pga.401.2019.01.06.11.31.09; Sun, 06 Jan 2019 11:31:23 -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 S1726453AbfAFT3E (ORCPT + 99 others); Sun, 6 Jan 2019 14:29:04 -0500 Received: from smtp3-g21.free.fr ([212.27.42.3]:34719 "EHLO smtp3-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726050AbfAFT3E (ORCPT ); Sun, 6 Jan 2019 14:29:04 -0500 Received: from localhost.localdomain (unknown [IPv6:2a02:8108:4840:8f74:143e:fcd5:beb7:2140]) (Authenticated sender: albeu) by smtp3-g21.free.fr (Postfix) with ESMTPA id 48DF713F8C1; Sun, 6 Jan 2019 20:28:56 +0100 (CET) From: Alban Bedel To: Srinivas Kandagatla Cc: linux-kernel@vger.kernel.org, Alban Bedel Subject: [PATCH 5/8] nvmem: core: Properly handle connection ID in of_nvmem_device_get() Date: Sun, 6 Jan 2019 20:28:17 +0100 Message-Id: <20190106192820.12558-6-albeu@free.fr> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190106192820.12558-1-albeu@free.fr> References: <20190106192820.12558-1-albeu@free.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org of_nvmem_device_get() would crash if NULL was passed as a connection ID. Rework this to use the usual sementic of assuming the first connection when no connection ID is given. Furthermore of_nvmem_device_get() would return -EINVAL when it failed to resolve the connection, making it impossible to properly implement an optional connection. Return -ENOENT instead to let the caller know that the connection doesn't exists. Signed-off-by: Alban Bedel --- drivers/nvmem/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index a7556b20cff4..28e01a9876c6 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -839,13 +839,14 @@ struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id) { struct device_node *nvmem_np; - int index; + int index = 0; - index = of_property_match_string(np, "nvmem-names", id); + if (id) + index = of_property_match_string(np, "nvmem-names", id); nvmem_np = of_parse_phandle(np, "nvmem", index); if (!nvmem_np) - return ERR_PTR(-EINVAL); + return ERR_PTR(-ENOENT); return __nvmem_device_get(nvmem_np, NULL); } -- 2.19.1