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 {