From patchwork Thu Dec 21 17:34:18 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: 182366 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp571235dyi; Thu, 21 Dec 2023 09:35:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IExAz2RqDXXE+seosVeLa832zuYH/pLzGgtX/Y9ZxgCrBCHXmLXtZ2htJL2fjoCvF0Lfzg+ X-Received: by 2002:a05:622a:1a9e:b0:427:8575:c25 with SMTP id s30-20020a05622a1a9e00b0042785750c25mr84541qtc.63.1703180138992; Thu, 21 Dec 2023 09:35:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703180138; cv=none; d=google.com; s=arc-20160816; b=O93TbiqbTgf/oin5oB41QacrmJp2H8JujOKhZIkih3C80VYcnn+iFB1TOocWJ2Wcx4 /i/BCF63tXYN7rQbv7Z4VyIzt6HNcJ/o5fWE+vMfJ8hwEMBsruii/suB7HysA5PAhTrV 6X72y3KaQ8kzUZnf/FUdSIrIt3ALzVJV+dHIeT0YPuJxRMSFuEQFL+9NNAy785fvpOav mLLRyCx2QXzQBXpjJKEpunFtUZAywbdA1rS+c3VSc2Rn9/fjK4QZ1LW3DWrFEfztOFXF VxdWfutj7l619v/15CW7pqY9zhPRgqFOQr4sg1v3fjDfWp2ja1q2IWvrxBvgx7Vr9grA 5c9w== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vqokOpCdOnYJH+v0vSqloYMckBtHhTjUM2t6QO3puqo=; fh=dfLNqWOtm0UaHb8GCHMuBSVlbZCi7eV095mQO5nOqs8=; b=y5wU6TRDfXDX754fpbzbarbLoXEaEYTkDK9MGoqDQq/KZ9xY9kaJmmgOQkcHpgtMZN AJulLALp+ZhlV2KaOemBsT1iNs3EodPAFcL+Qg0UCxWK3k+f62YSAO90mebecFVvzZy1 RqvDUPleU1roqUkGwhFzthQAMhiOcyf0cZK4kHMVLxU0kt6hXjN697ZK7IGFoCTk2O+0 6qWYFrgJMiuCD8M8cerQFH4r0NnoqWRsb4Ew1JDi6u6c4Ccx1QYs5KUPMx37S14PnZTz guNtzwLc6jJ8Wc8MmS35P+cLLEWu0GibDpmTLj015Xz3k1AiHANMa4eOlC3lMRb+gWT+ OiRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RQGWUKs1; spf=pass (google.com: domain of linux-kernel+bounces-8857-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8857-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b16-20020ac85bd0000000b00425c1e87b6bsi2509169qtb.487.2023.12.21.09.35.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 09:35:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8857-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RQGWUKs1; spf=pass (google.com: domain of linux-kernel+bounces-8857-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8857-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 375D41C26149 for ; Thu, 21 Dec 2023 17:35:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B50064A9C; Thu, 21 Dec 2023 17:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RQGWUKs1" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 D4CFA634EA; Thu, 21 Dec 2023 17:34:37 +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-ej1-f45.google.com with SMTP id a640c23a62f3a-a236d77dceeso132142966b.2; Thu, 21 Dec 2023 09:34:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703180076; x=1703784876; darn=vger.kernel.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=vqokOpCdOnYJH+v0vSqloYMckBtHhTjUM2t6QO3puqo=; b=RQGWUKs1PmWexBqA7biqdNoRe0mVG45Fs2gpqKE0Ot6imjGHCNTJ+RE9HJM8IAvkKx z9Q+sjJ1wGGC5yBGFaXzLPfhQw711NDNAlfsYXUmgfEzbygJdP1hnjwjLPgVAYwx1arI qDOTMoiaSuDiH86Vzq25qd0QWOM4wpJcBKvmD9RVS6ia2tFPhXVu5ogkuEagd+EGAel2 dl9RqItJsmTeaJQIWXVylZIYpka8purV01MmYdYWCR3feHpGxGuduffsVVQ8SZf4Gl0L 1BkRRoft4jL9+C54wsCetBcAdAenmMus4ASWmaha4II7jWHt0yobbwc6HDf5gJ0i++HT JrcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703180076; x=1703784876; 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=vqokOpCdOnYJH+v0vSqloYMckBtHhTjUM2t6QO3puqo=; b=G3l+Jv+Ad8DqbMM58fCy0C4PjuVyBe4yPcATTpK24+7cH/qla8/m6DqAKdjlHV/IM5 yGavr2EsrsWT8pInStArfK1TVtnKpkPRzU9npAEfwq5M2xzZT2hxcWGNgYqssCor17hX JlmFB1nSE0AS/ifCB5AxsbKe/8q11Njh4+eCQ0X7OC489LDWvJJ6rh1rPTUDMfmFGC40 kEyvxMUYMGbwihSixUkhcZZcU3LyStIVYKi7LL5WPG9e2WJrJFPaVuSOMWwWD6hseDMT QYe9hPpPeAU4V18xVbnzCim8Gxhn2mFMxKHwP9dGQOWI3+wXPkT4GlXMql6qcpkhxnvC RePg== X-Gm-Message-State: AOJu0YwS54ZZZGUwZ4NuUvsBr8/e48kh/2FKumN5udMRqqiRGjpvyBxh Ph6zblRgTLkloE+hOBR3Xek= X-Received: by 2002:a17:906:1059:b0:a23:56a3:f51e with SMTP id j25-20020a170906105900b00a2356a3f51emr22883ejj.198.1703180075704; Thu, 21 Dec 2023 09:34:35 -0800 (PST) Received: from localhost.lan (031011218106.poznan.vectranet.pl. [31.11.218.106]) by smtp.gmail.com with ESMTPSA id z25-20020a1709060ad900b00a23499f1d7dsm1176118ejf.209.2023.12.21.09.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 09:34:35 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Greg Kroah-Hartman , Michael Walle , Miquel Raynal , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V3 3/6] nvmem: u-boot-env: use nvmem_add_one_cell() nvmem subsystem helper Date: Thu, 21 Dec 2023 18:34:18 +0100 Message-Id: <20231221173421.13737-3-zajec5@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231221173421.13737-1-zajec5@gmail.com> References: <20231221173421.13737-1-zajec5@gmail.com> 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: 1785913817225647940 X-GMAIL-MSGID: 1785913817225647940 From: Rafał Miłecki Simplify adding NVMEM cells. Signed-off-by: Rafał Miłecki Reviewed-by: Miquel Raynal --- V3: Split PATCH 3/3 into two drivers/nvmem/u-boot-env.c | 55 +++++++++++++++----------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c index c4ae94af4af7..dd9d0ad22712 100644 --- a/drivers/nvmem/u-boot-env.c +++ b/drivers/nvmem/u-boot-env.c @@ -23,13 +23,10 @@ enum u_boot_env_format { struct u_boot_env { struct device *dev; + struct nvmem_device *nvmem; enum u_boot_env_format format; struct mtd_info *mtd; - - /* Cells */ - struct nvmem_cell_info *cells; - int ncells; }; struct u_boot_env_image_single { @@ -94,43 +91,36 @@ static int u_boot_env_read_post_process_ethaddr(void *context, const char *id, i static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf, size_t data_offset, size_t data_len) { + struct nvmem_device *nvmem = priv->nvmem; struct device *dev = priv->dev; char *data = buf + data_offset; char *var, *value, *eq; - int idx; - - priv->ncells = 0; - for (var = data; var < data + data_len && *var; var += strlen(var) + 1) - priv->ncells++; - - priv->cells = devm_kcalloc(dev, priv->ncells, sizeof(*priv->cells), GFP_KERNEL); - if (!priv->cells) - return -ENOMEM; - for (var = data, idx = 0; + for (var = data; var < data + data_len && *var; - var = value + strlen(value) + 1, idx++) { + var = value + strlen(value) + 1) { + struct nvmem_cell_info info = {}; + eq = strchr(var, '='); if (!eq) break; *eq = '\0'; value = eq + 1; - priv->cells[idx].name = devm_kstrdup(dev, var, GFP_KERNEL); - if (!priv->cells[idx].name) + info.name = devm_kstrdup(dev, var, GFP_KERNEL); + if (!info.name) return -ENOMEM; - priv->cells[idx].offset = data_offset + value - data; - priv->cells[idx].bytes = strlen(value); - priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name); + info.offset = data_offset + value - data; + info.bytes = strlen(value); + info.np = of_get_child_by_name(dev->of_node, info.name); if (!strcmp(var, "ethaddr")) { - priv->cells[idx].raw_len = strlen(value); - priv->cells[idx].bytes = ETH_ALEN; - priv->cells[idx].read_post_process = u_boot_env_read_post_process_ethaddr; + info.raw_len = strlen(value); + info.bytes = ETH_ALEN; + info.read_post_process = u_boot_env_read_post_process_ethaddr; } - } - if (WARN_ON(idx != priv->ncells)) - priv->ncells = idx; + nvmem_add_one_cell(nvmem, &info); + } return 0; } @@ -209,7 +199,6 @@ static int u_boot_env_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; struct u_boot_env *priv; - int err; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -224,17 +213,15 @@ static int u_boot_env_probe(struct platform_device *pdev) return PTR_ERR(priv->mtd); } - err = u_boot_env_parse(priv); - if (err) - return err; - config.dev = dev; - config.cells = priv->cells; - config.ncells = priv->ncells; config.priv = priv; config.size = priv->mtd->size; - return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config)); + priv->nvmem = devm_nvmem_register(dev, &config); + if (IS_ERR(priv->nvmem)) + return PTR_ERR(priv->nvmem); + + return u_boot_env_parse(priv); } static const struct of_device_id u_boot_env_of_match_table[] = {