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: 180886 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1883460dyi; Tue, 19 Dec 2023 04:02:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9UqgeDcIXqsVQBgTFrvH3GraDl83Ybt5fp/fHJq2T9rG9wd/4eov5wkRIA96kmYl6Lcl6 X-Received: by 2002:a05:6a20:914b:b0:190:228e:4c11 with SMTP id x11-20020a056a20914b00b00190228e4c11mr9713418pzc.90.1702987330275; Tue, 19 Dec 2023 04:02:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702987330; cv=none; d=google.com; s=arc-20160816; b=yYeCTmCvnxt4CEVUrGXbes+YkD+sYtoAH56NmFckh1VxFYwXz1nFoDtRjb6CH7qFdC ygv1D/iSvjf5kSikeKwvgh1WffJrYOIcPuiVueScFCKtuktrIvA+jrlA2lCl6UYJVrJy ByLOoeCsjn/xPnIGsHllattPPk2NkxVjvMx+04Lu+MzXA8yHoK0Ur5hXA988Ml9+RbKb 4Hq3QkuT23LBcn1i3YBQP/FxpAx6L1rycmhnr2BjwAPRMEhv4BmOlp5A6S+NriUq/4k7 6wDW2WACiNBQdgxwoCkznEfIKHTfmNBueQYRLwLWEPJWTOGufX/nf62w+d49+Z1wdKhw s4tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=Ggc4MgLow8E4fR59OH6SNMuCU7W9ARSM1t4iHs9v3xw=; fh=QqsJB2wsj2uwf7b+bn803aXRbPtar25mYRjyWdDZX6g=; b=PdkqdMuqrfFrhm3DuF1VRv74r9DGkf2ybrKnhiVqOL31gZ7hI1VcEFznMPwTTuVib/ 9V9oAH/3YLQx5EpUrZt1YQP3vjfM/JBOtI4v3reGv89rrO1X1jYY+J2/GhuGbO5ES58M Wgz2lOLe89Q0UlBv3zdzq69kwLImcrqxAx71KlWyKKkgeuP/aIqodvEvpmpxD7rVfnf+ B8KlTMuZuMlmt2TPDw/2emK7Tlz89PO0EkqA/UlLxtygbfJW30DayOXK6zDNawNABY7w WPxev8hoqK2XVkafPK+cBISIN4PWr5jTQUyrBRwh0Lp5S7J4UlajY6Gb0CQipxTHkX8x XmXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Pu4R23wm; spf=pass (google.com: domain of linux-kernel+bounces-5133-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5133-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z186-20020a6333c3000000b005cd7fc2c654si5706163pgz.459.2023.12.19.04.02.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 04:02:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5133-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Pu4R23wm; spf=pass (google.com: domain of linux-kernel+bounces-5133-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5133-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EBC8F286E90 for ; Tue, 19 Dec 2023 12:02:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA0A11A732; Tue, 19 Dec 2023 12:01:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pu4R23wm" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 820231A58B for ; Tue, 19 Dec 2023 12:01:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-54c77e0835bso5425892a12.2 for ; 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=vger.kernel.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=Pu4R23wmRkGbtNwaOBlmVDK368m9BQRw5SwnCY23I9aTpkuh3Gfc1pfypjyTS/fS1C AksBEjnY3dZ9Jbzx7vlMdyIU496euKfIFCau2/ffLwqA7g0rN4USBpaEb4y4Hk0/oji9 3JMsS0jKhHXHqVNVRumVvV/IoujYQmAxZUo5HFwW++3qpr5MVTPTXs8/n7fMbatzfZIf 64Cwsxye0KPdXBidRmKGBULgu0p5htxGVmkO3bU3UO/roTZkgJtCXX98Go+BVWO5JaWU bbyj8csvUmRr3uslIZogfZXMX3TGxgR2PfrVwcvl052HAHduzg3iQD8x6azuOdCdq1YG xQcQ== 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=HVfYi7aIfUqB7M8K8xBgQzFsdU+reWi0N9uJZz0CX40nylFZZkPOD3Ejx8ygfTYTv3 RuduVRA9yyzfs+n+zJ6IZyn8LmAz6XIh5DiQ0Faw0VQAOE6irfUPey6/SwcpHmSqH/Zg PN1vzzzlUrbB/dni3xzrzU6iyP4Lz4wz89otUQTaCuYzXxuNzLKJ6zhkOPrcwwiG06GE tI/XrvCvgtAfzuTaeJMgGLD+6ieqCGsRMZTLKUAt+SpaZ/2WaBxNrJoW6viUC7F6cRrV OCx0so6KvEnfF8w7YqT63JmGX/WEU2FFzooHdOxRz5i8gc799WUs6us+nyqorKIaSRjX RhqA== X-Gm-Message-State: AOJu0YwwNCA/rz2loWz15D4JzfmeueTmMu5WT4efXL66HzRK13QBgNL4 YrPcVw29ZLV5Nfr5sfSKhwU= 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785711642644917813 X-GMAIL-MSGID: 1785711642644917813 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 {