From patchwork Wed Mar 1 15:22:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 62963 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3694079wrd; Wed, 1 Mar 2023 07:28:07 -0800 (PST) X-Google-Smtp-Source: AK7set/Y4GO6mqUnPyEVGWk0veebw2FPNXHKDC3DdaSo0cJfWXKZbPwaqi+db3+Dbb+GtBEXZPUg X-Received: by 2002:a17:906:6b91:b0:8b1:7e88:c20f with SMTP id l17-20020a1709066b9100b008b17e88c20fmr7666056ejr.15.1677684486776; Wed, 01 Mar 2023 07:28:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677684486; cv=none; d=google.com; s=arc-20160816; b=LsD2MZXdMKqM/w3ebwZv4sbnuICvseNLiC+BNSy08EEaoGkX3BCjRsnxcFZaKzI4Io lnzPtNgxw05J3M8joMwLxZDjsnKo58ahrxhWDLbvIaH62JZ/dRyRa40i3JJCHwK9+yXg GhQ8jaE5e8366HX8nuNNo4O+CmqA5F7BjCBzVGOiq2NFONWBgpVhKr3gVZa3vRBtpjZv TYVz9Qd6N/d4CfJdu3AwFbHiJxacMJibq51E7717SilKge48qvp34yXUv0DJvUtY0j3F dNm+bQQZb84zrKo5dyt/h9RY9wa+ocp2AR4eCqD5v8PKxeCO+CdwaQrtPpZx6kGipxOF EYWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GuIzUxO4lQXjU9mkGsm3TUZaxNfzhaCKElzogF6isV0=; b=dHYmAGY4oZkFbDObi0/7zCE5ce/HicN9xWdPYVUF3Vs2wuYJ9nlE9I3D+OtJ11KvEC 1zTryHYRAMK1ZLPfY6fvnfRc5AxnrxCNnYIfPLrWpnk3GRDxIEG/gXjPp6f/ja2ztUPG 1PrmfcGIUgmvJUsh5hYlpz96QOswvmATzT6RZYJlF40haEWCuZLNK+1bShV3YTMLIaMF 9Np8Ot+KMo4lw+gkSy/TIt3g7c6dGj22rZofJy6/FcM3O7cwisLZTxQc3xubEEh9lchc YEsiyZLrgCCVQN/r5GntdMXRvzwsJBsWYsMEkKbhw/HuvaTi+9wfI/FrqLQkCU+vjVfv prqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=fMXMYqkW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bl5-20020a170906c24500b008b8a4ed82fcsi15587720ejb.947.2023.03.01.07.27.37; Wed, 01 Mar 2023 07:28:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=fMXMYqkW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230359AbjCAPXH (ORCPT + 99 others); Wed, 1 Mar 2023 10:23:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230311AbjCAPWu (ORCPT ); Wed, 1 Mar 2023 10:22:50 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E649442BD9; Wed, 1 Mar 2023 07:22:48 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 9DD6960013; Wed, 1 Mar 2023 15:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GuIzUxO4lQXjU9mkGsm3TUZaxNfzhaCKElzogF6isV0=; b=fMXMYqkWJ3UjHLEh6WJlxZ/yVh1q0t2kjD0aviSY8eAz9MuvL53UfdXKX4S4xAwjSWfFNn sDrjZT/U5TPdJ7Eqc4rmRZiV8pM23fZbc4f2RY5cI59HOAp3BT7Psti1VTHB69Un/OKV+K DZE/pfCJLZMu/u7aKcd3Odj9nOZpNB/EPouA4si1lgYNw4M/JAi/MrmLmDHo69R3OA3Wcd O6a/tnNE0E7IoAB7wBhUX+uNvWDi12uTYaeKoc2kLL3cNxS4W2VmCO8TAng9J4+XFUEUkF VFwRQ0JVRVsFIKrDgcViHCC763rFlu06DgIttgms+3/LrHjGduUhjt/iFTwbQg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 5/8] nvmem: core: Handle the absence of expected layouts Date: Wed, 1 Mar 2023 16:22:36 +0100 Message-Id: <20230301152239.531194-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759179688447235358?= X-GMAIL-MSGID: =?utf-8?q?1759179688447235358?= Make nvmem_layout_get() return -EPROBE_DEFER while the expected layout is not available. This condition cannot be triggered today as nvmem layout drivers are initialed as part of an early init call, but soon these drivers will be converted into modules and be initialized with a standard priority, so the unavailability of the drivers might become a reality that must be taken care of. Let's anticipate this by telling the caller the layout might not yet be available. A probe deferral is requested in this case. Please note this does not affect any nvmem device not using layouts, because an early check against the "nvmem-layout" container presence will return NULL in this case. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 16044377a41d..a66c37a03a36 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -762,7 +762,7 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister); static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) { struct device_node *layout_np, *np = nvmem->dev.of_node; - struct nvmem_layout *l, *layout = NULL; + struct nvmem_layout *l, *layout = ERR_PTR(-EPROBE_DEFER); layout_np = of_get_child_by_name(np, "nvmem-layout"); if (!layout_np) @@ -944,6 +944,13 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) * pointer will be NULL and nvmem_layout_put() will be a noop. */ nvmem->layout = config->layout ?: nvmem_layout_get(nvmem); + if (IS_ERR(nvmem->layout)) { + rval = PTR_ERR(nvmem->layout); + nvmem->layout = NULL; + + if (rval == -EPROBE_DEFER) + goto err_teardown_compat; + } if (config->cells) { rval = nvmem_add_cells(nvmem, config->cells, config->ncells); @@ -976,6 +983,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_remove_cells: nvmem_device_remove_all_cells(nvmem); nvmem_layout_put(nvmem->layout); +err_teardown_compat: if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_put_device: