From patchwork Tue Dec 19 12:01:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 13498190 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 15B01C41535 for ; Tue, 19 Dec 2023 12:01:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=x5XP9JmdWFoD2ftkQ29me9OFcymxw+4qZapfpwiEUYs=; b=oZ11DXt90a9pAe khevTfvoeNob+J3s49E3wEGz2IduOls2vsgkVmjsURJmshlB36AailUJicUlaAYbXxO8k27Zj0+66 UHL2BGXF2+72IvZPNUVJuxE1hGOD4XximTfNP/eo36VEMLr0i3jeLZ9QEr/O3cqQJo0pyMlDQ7VQD i5MCj78FWFLT6Ta/0Hjgd+m9ljp/VPEJoCGNbDIQY0BjjF01dTS0raeh5czVbXSepuZL5xOZERBNk Gcs00XF5HLIBEwbi6ncjobkM+GFvQ3+pDD8YTklrqC2I7a3g5wVONGy3IiH5G/sAqSXXH9CJ5Vvlz sxPgTiB++LsercIc/lrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFYmt-00Dwxb-2Y; Tue, 19 Dec 2023 12:01:27 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFYmp-00Dwtc-1b; Tue, 19 Dec 2023 12:01:25 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-54f4f7d082cso5443090a12.0; Tue, 19 Dec 2023 04:01:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702987280; x=1703592080; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Ggc4MgLow8E4fR59OH6SNMuCU7W9ARSM1t4iHs9v3xw=; b=TOITo50TmPY6AD9XG2YoMXdptBITMyVACn889j1uF3xYdRbEvlGleyjtnPOscA3iba vEz2u0iksDguOOj8HZClGmEOPj8JxrAipIIeWRMRzXiTJPKDZn6LGXAeEv5HX/RExvDI rEHgBDpaICoPIEKebqDP05qlpXnqRbqwlqIiAEQqVfzah0Gg4MxxnkLTFYRif5r+FYQk rYcT5B9KnTQFPdgpFTTO0Jrc+RFwQbmkexX1+uPFQvQQBrL7c9V3gaiOcPEtmKSk4UcB GFs2UbhFlMekVBoRPRMzYQm8T9C/zVtEf7GatF3wyTCtLMyyngrAwyUDE/igwhQNnIkG +cPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702987280; x=1703592080; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ggc4MgLow8E4fR59OH6SNMuCU7W9ARSM1t4iHs9v3xw=; b=cwR13l6EvSDvLs93qKPVgf6D5lvt4pOZlgcSSIemzl4SMktOUS1lf9VGqJe2FMWH8k XZkEr9vXqCY+9UsqrC/4qbO8rJpfBALotisAVKZDdOfDdozLS+BXBdOQwjq40yq5I8ZP BlU212Iv+4A1sn06e0KWfhC57hLLYuSsUztRVfQwKG5JsDfXHIeC4n+jFNfXtE77gJpV AhnvsTLh6Mhgj3rHxznPzVyvxwiczqmI0U6X6mgj8+jfWKKw9/QhcUC5Nwsut0K8UAg9 BkzpLkE6xqefvdQHKHUVcsIP9Svkof1E+gx9ZsrABE83CFGsReAbT4E5GYwqZEv7BEUW fCwQ== X-Gm-Message-State: AOJu0Yx8AK6klNK736pmpujlqueJ2Y4KpuGOloVtZJLHsqKjtoahRdu6 NSP/VmJA6Ph2Gf85vUpBI+Y= X-Google-Smtp-Source: AGHT+IGbWu9nYmKMlQOgTvvIAYGTbf9goRDVatn2xCQG7tStTbISUYi0agdhw2nFSCl3wzgngLUGMA== X-Received: by 2002:a17:906:c3:b0:a1f:830a:b621 with SMTP id 3-20020a17090600c300b00a1f830ab621mr8866169eji.109.1702987279434; Tue, 19 Dec 2023 04:01:19 -0800 (PST) Received: from localhost.lan (031011218106.poznan.vectranet.pl. [31.11.218.106]) by smtp.gmail.com with ESMTPSA id ux4-20020a170907cf8400b00a230f3799a4sm6767478ejc.225.2023.12.19.04.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 04:01:19 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Greg Kroah-Hartman Cc: Michael Walle , Miquel Raynal , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH v6.8 1/2] nvmem: layouts: refactor .add_cells() callback arguments Date: Tue, 19 Dec 2023 13:01:03 +0100 Message-Id: <20231219120104.3422-1-zajec5@gmail.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231219_040123_540669_E7E94F6C X-CRM114-Status: GOOD ( 18.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki Simply pass whole "struct nvmem_layout" instead of single variables. There is nothing in "struct nvmem_layout" that we have to hide from layout drivers. They also access it during .probe() and .remove(). Thanks to this change: 1. API gets more consistent All layouts drivers callbacks get the same argument 2. Layouts get correct device Before this change NVMEM core code was passing NVMEM device instead of layout device. That resulted in: * Confusing prints * Calling devm_*() helpers on wrong device * Helpers like of_device_get_match_data() dereferencing NULLs 3. It gets possible to get match data First of all nvmem_layout_get_match_data() requires passing "struct nvmem_layout" which .add_cells() callback didn't have before this. It doesn't matter much as it's rather useless now anyway (and will be dropped). What's more important however is that of_device_get_match_data() can be used now thanks to owning a proper device pointer. Signed-off-by: Rafał Miłecki Reviewed-by: Michael Walle Reviewed-by: Miquel Raynal --- Those changes complete layouts refactoring process so I'd very much like them to go with the rest of refactoring stuff to v6.8. It's difficult to add Fixes tag due to the nature of refactoring. Callback .add_cells() existed even before refactoring so I'm not sure what commit would be fair to blame. Srini, Greg: could you see if this could still make it into v6.8? drivers/nvmem/core.c | 2 +- drivers/nvmem/layouts/onie-tlv.c | 4 +++- drivers/nvmem/layouts/sl28vpd.c | 4 +++- include/linux/nvmem-provider.h | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index ba559e81f77f..441d132ebb61 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -854,7 +854,7 @@ int nvmem_layout_register(struct nvmem_layout *layout) return -EINVAL; /* Populate the cells */ - ret = layout->add_cells(&layout->nvmem->dev, layout->nvmem); + ret = layout->add_cells(layout); if (ret) return ret; diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c index b24cc5dcc6ee..9d2ad5f2dc10 100644 --- a/drivers/nvmem/layouts/onie-tlv.c +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -182,8 +182,10 @@ static bool onie_tlv_crc_is_valid(struct device *dev, size_t table_len, u8 *tabl return true; } -static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem) +static int onie_tlv_parse_table(struct nvmem_layout *layout) { + struct nvmem_device *nvmem = layout->nvmem; + struct device *dev = &layout->dev; struct onie_tlv_hdr hdr; size_t table_len, data_len, hdr_len; u8 *table, *data; diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c index b8ffae646cc2..53fa50f17dca 100644 --- a/drivers/nvmem/layouts/sl28vpd.c +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -80,8 +80,10 @@ static int sl28vpd_v1_check_crc(struct device *dev, struct nvmem_device *nvmem) return 0; } -static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvmem) +static int sl28vpd_add_cells(struct nvmem_layout *layout) { + struct nvmem_device *nvmem = layout->nvmem; + struct device *dev = &layout->dev; const struct nvmem_cell_info *pinfo; struct nvmem_cell_info info = {0}; struct device_node *layout_np; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 6fe65b35ea97..81a67642ac55 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -173,7 +173,7 @@ struct nvmem_cell_table { struct nvmem_layout { struct device dev; struct nvmem_device *nvmem; - int (*add_cells)(struct device *dev, struct nvmem_device *nvmem); + int (*add_cells)(struct nvmem_layout *layout); }; struct nvmem_layout_driver { From patchwork Tue Dec 19 12:01:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 13498191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86911C41535 for ; Tue, 19 Dec 2023 12:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6IuFuraPoyxt/6lTY9hfLzV3gqyOVAijzfO8Vbx/9ZA=; b=SQr1wOLUD1Inr7 sDh9yTeuX39yzAVeIDnijIdpoqVJjJD/yHaq5DY5lQnlwmb2rgw/pUD0OY4wAOhNDg7TyN69WvIMS JLMgQLW7ZWDwvn9pancHZujv8z1Ghr4cs/dT/qGi1FtjsbvZRlIG9iBKPJsy0NXRnBkqG93QUJ74e duQFv9CfWyB/TylItwr5O11qu8nNc49knIwxHlcGXeIpJ0V9eANhWbhoNL2mB2U/0sXiYuMHqE7y7 9YT467PmVyKC4KvzrALnjv1PJUtSHGt2zN16rNgn5mzqFWO7tIv1HFdkVCbjHeckpxaXWkNIVFNJ3 fdmB2PRZXSxphEw3Limw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFYn1-00Dx0U-1m; Tue, 19 Dec 2023 12:01:35 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFYms-00Dwvq-33; Tue, 19 Dec 2023 12:01:28 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40d190df5d0so26929225e9.3; Tue, 19 Dec 2023 04:01:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702987283; x=1703592083; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T7yEMgXZhKtlt+r30N1IJsOJuMAaTYKKq9iU4tTYh4A=; b=dC8lvo8B4HByghfHuHo2l3QHTFIt+4vQl6NQmG0/3Mk/8J0qtbvosTcckM4HZcjGck 6VdqJ7BT146Qq8fPMUhoRtyXggKCBV8E2/lbOiCYJAIqFbmexoZnqXBeiu9XHhDoPGJv 3IC2p4DdIBcIJ12ClNcUmm24tHcac7mkiYgt+JxIMIoH4CQwBdLqtDdhCARrPnIJkhje Id/TEuLpGsWeyRupc+KTYpKu6anCKS3BHbmE6GAb/RMe7DNDENC2xFlHgTeCiVLrbA2A P0NcT/4XyXgPj5WDeTa2dppw0hdXJAtKzyRgyBxxTKITHpDSSYgEa0AVaJm1/VZBGHal 8tqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702987283; x=1703592083; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T7yEMgXZhKtlt+r30N1IJsOJuMAaTYKKq9iU4tTYh4A=; b=Ymp0r0qTAMPNbd1IUgtUWYDWyX8tFz6aVCw/GgicdfSRJerDJlqr1P3ybaGlktFVTQ 7mqrrE8KV7JSMKton1oD/xiujl2TYA+Sj9RwMUoGJWSWarWF/hZJBnBzrMMv3+VxArQx Vl/sKoFnZMQLz8gFnbip4Vaws6+W5nfDX+T9/at8qj6GaLeFGqoAx7D3xrleaUxLqHJi wZpC7WGuvd1rFohxg0TW7VIm0i1ltDg4SBIRVvqUWy8G3OOpuKIQkmDpjnePuf5jFdkT vgpJpA5TZdtPyTTPMTQBM9jwDKgi0XG2aZ72DNeB/75MLW3bERx+x7SBLnMophSnGfQD enmQ== X-Gm-Message-State: AOJu0YxPyMSHk5d37IG+S6dEzZHlb1ZldPzEjV+w52tBnVgpWxLVTr+8 KCebeZSbPLD/82GDUkr9QeQ= X-Google-Smtp-Source: AGHT+IFacrsz/WxyyAmEwuqg1BB6bNHm96HPr0zlPC74PGs1gxTM16a3p4tpZQe9CQsLj/7ekjHxXA== X-Received: by 2002:a05:600c:d4:b0:40b:5e59:c55b with SMTP id u20-20020a05600c00d400b0040b5e59c55bmr9283867wmm.133.1702987283001; Tue, 19 Dec 2023 04:01:23 -0800 (PST) Received: from localhost.lan (031011218106.poznan.vectranet.pl. [31.11.218.106]) by smtp.gmail.com with ESMTPSA id ux4-20020a170907cf8400b00a230f3799a4sm6767478ejc.225.2023.12.19.04.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 04:01:22 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Greg Kroah-Hartman Cc: Michael Walle , Miquel Raynal , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH v6.8 2/2] nvmem: drop nvmem_layout_get_match_data() Date: Tue, 19 Dec 2023 13:01:04 +0100 Message-Id: <20231219120104.3422-2-zajec5@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231219120104.3422-1-zajec5@gmail.com> References: <20231219120104.3422-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231219_040127_025493_4E872DDA X-CRM114-Status: GOOD ( 11.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki Thanks for layouts refactoring we now have "struct device" associated with layout. Also its OF pointer points directly to the "nvmem-layout" DT node. All it takes to get match data is a generic of_device_get_match_data(). Signed-off-by: Rafał Miłecki Reviewed-by: Michael Walle Reviewed-by: Miquel Raynal --- drivers/nvmem/core.c | 13 ------------- include/linux/nvmem-provider.h | 10 ---------- 2 files changed, 23 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 441d132ebb61..4ed54076346d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -876,19 +876,6 @@ void nvmem_layout_unregister(struct nvmem_layout *layout) } EXPORT_SYMBOL_GPL(nvmem_layout_unregister); -const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, - struct nvmem_layout *layout) -{ - struct device_node __maybe_unused *layout_np; - const struct of_device_id *match; - - layout_np = of_nvmem_layout_get_container(nvmem); - match = of_match_node(layout->dev.driver->of_match_table, layout_np); - - return match ? match->data : NULL; -} -EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data); - /** * nvmem_register() - Register a nvmem device for given nvmem_config. * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 81a67642ac55..f0ba0e03218f 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -205,9 +205,6 @@ void nvmem_layout_driver_unregister(struct nvmem_layout_driver *drv); module_driver(__nvmem_layout_driver, nvmem_layout_driver_register, \ nvmem_layout_driver_unregister) -const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, - struct nvmem_layout *layout); - #else static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c) @@ -238,13 +235,6 @@ static inline int nvmem_layout_register(struct nvmem_layout *layout) static inline void nvmem_layout_unregister(struct nvmem_layout *layout) {} -static inline const void * -nvmem_layout_get_match_data(struct nvmem_device *nvmem, - struct nvmem_layout *layout) -{ - return NULL; -} - #endif /* CONFIG_NVMEM */ #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)