From patchwork Tue Dec 19 17:40:24 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: 181162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2111593dyi; Tue, 19 Dec 2023 09:51:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IF822U7jKEHXbjW40GlhqEVEtF6LbqG42i0yVsp8ZewN9Z4sxN+N7a9NxFOOyMyk3qeeNqt X-Received: by 2002:a05:6512:3c8d:b0:50e:4146:dcf8 with SMTP id h13-20020a0565123c8d00b0050e4146dcf8mr1389458lfv.133.1703008269596; Tue, 19 Dec 2023 09:51:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703008269; cv=none; d=google.com; s=arc-20160816; b=OlW43MeXLrizuYcWqYM7stRzq5Reiqrg09obCzTR6FuZFZuRFUFuvKI1EFkDhKBu9E jKKXHJG5PnKFbmY3tOziQ+uoy2hGNWfveTSyW/k/U6cfT4E2GTpVwWCWfERTgDHb1ZfF RF+YwfIdfJTucK4L/G/B8V+GMBh6edCwPcHWyjstlwyHordokpRaOHlo/MPF7hObMxKl iU1RFrGx8nxzvJYNlU/L2Qoa55nz3a0IR8wK3mVoi3VkCN1FIQcNnLLSnZ56PaetCCdb 9v9dLnAyOIM2ViUDaVb7fgoL+ePbvmLWFPrNDNktXn/x1Rn/WD1WKrpg6jof0rBxd9GI 16xw== 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=lvbpVGdOkFoSIrqGEOI2u72GgRBjNjQRomAfCiRlrrE=; fh=dfLNqWOtm0UaHb8GCHMuBSVlbZCi7eV095mQO5nOqs8=; b=qmUoL56eX3vM2mwkLuhc3ubf7cofdOOzjVtWVC1tR0IV0okH5QqCS9kf7yIhBGq1a7 Bn+rTQnd88Qm1UVMOqmGh6Tj4T8Gdw6oZX3jXwv/L0J2leQn7grW0ufign7Rch3VHuyS Mp9UJZrW5kfLUiMLUXcdWeZwNoUffFNWPRTTiEzplDybaKbUlQBEMLOXIXcBpQ/GY8Yw TQbOXZ1Rl2srdK10+xZzXQhF7uiHsyqGDzFYzV/MUqALBrpeQ2Keu4SnQI0qiXgrp5cC f1CjAYX7SVYJ4YyX2qsCwMPUrfDHT9L9aO8OJMk78d2/oFZQQNGKcVYhPo3whxIpT0sP KJug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jL598i1n; spf=pass (google.com: domain of linux-kernel+bounces-5706-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5706-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e18-20020a170906045200b00a24901b6057si631769eja.392.2023.12.19.09.51.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 09:51:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5706-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jL598i1n; spf=pass (google.com: domain of linux-kernel+bounces-5706-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5706-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 am.mirrors.kernel.org (Postfix) with ESMTPS id F320F1F27663 for ; Tue, 19 Dec 2023 17:41:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D4E238F85; Tue, 19 Dec 2023 17:40:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jL598i1n" 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 D9E6137D02; Tue, 19 Dec 2023 17:40:45 +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-a235500d0e1so322067266b.2; Tue, 19 Dec 2023 09:40:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703007644; x=1703612444; 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=lvbpVGdOkFoSIrqGEOI2u72GgRBjNjQRomAfCiRlrrE=; b=jL598i1nG6qrlZgp6X8/F0jOHeTsKWpXzkau1Thp1dbXEsq+V7ECjJ+7Kf+p8e29E6 9UwsDwK7JBDiV9Dvs4KCg/vIaRgA0rBTSpe3kaC+Xu9pB0HX9xfdJbJf61gEucwlhXjL 1vWLlFZMunozo8iA2yrRGdflpgk3MWwJyVsfBqRDKNxE7KddLH7Kj4tNzLCJRyEyCdCI RalV3SJaKRft8kVthhNg90CmnEpSFOsnqNYH5RRwwm/WewdSXg577K8BubxjqS3F5GIc g4QpRzIn8pWXMz/2fpVEI9+u7m67VQIzOnT8Og2sxUMQ6j+cOM6BmwUSFNlXRi3Njx06 fufQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703007644; x=1703612444; 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=lvbpVGdOkFoSIrqGEOI2u72GgRBjNjQRomAfCiRlrrE=; b=Cj7cwxG9dYiKNqB3EaWkZBDr1kyRhTQiE83cseP0XH4y+pAU45E1pUYrdYOjQeG8jd nJY73abE5CRnDopl4Lj1dtKwMG/eT3bNrkrKjLUy/VNLq5ek7BfPGHshhJ3umzg/JBCe Z5l28cS0OymiE/IUkL1w+gm47fopBJu+R8SF7y4k1LaByq/7HsVP6n1jZnpz8xb+s6DG CLE+GrJBNRWUuYe5yEaB+XGIpJnbdYLvqu/GWgJzOTewV2Z8MWXy+Yzp4uUhM5meyL5T 2TVN4zQNStH0q9a9ozABlKkkhdh/32aedo9R0GQh4N5bVwL1Ls7+yrsEV3LcHksQ7wf6 hR1w== X-Gm-Message-State: AOJu0YyaIKBY3SvZkYOpc5cK6y1w79Z38379K5Vd5tBPIC4SkPvXiPI8 qQG3oJAzDdBuFmQ7gGWn+c8= X-Received: by 2002:a17:906:da04:b0:a26:8919:6d99 with SMTP id fi4-20020a170906da0400b00a2689196d99mr274634ejb.2.1703007643985; Tue, 19 Dec 2023 09:40:43 -0800 (PST) Received: from localhost.lan (031011218106.poznan.vectranet.pl. [31.11.218.106]) by smtp.gmail.com with ESMTPSA id tx27-20020a1709078e9b00b00a1c85124b08sm15834840ejc.94.2023.12.19.09.40.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 09:40:43 -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 V2 4/5] nvmem: u-boot-env: improve coding style Date: Tue, 19 Dec 2023 18:40:24 +0100 Message-Id: <20231219174025.15228-4-zajec5@gmail.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231219174025.15228-1-zajec5@gmail.com> References: <20231219174025.15228-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: 1785733599248838565 X-GMAIL-MSGID: 1785733599248838565 From: Rafał Miłecki 1. Prefer kzalloc() over kcalloc() See memory-allocation.rst which says: "to be on the safe side it's best to use routines that set memory to zero, like kzalloc()" 2. Drop dev_err() for u_boot_env_add_cells() fail It can fail only on -ENOMEM. We don't want to print error then. 3. Add extra "crc32_addr" variable It makes code reading header's crc32 easier to understand / review. Signed-off-by: Rafał Miłecki Reviewed-by: Miquel Raynal --- V2: New patch with suggestions from Miquel drivers/nvmem/u-boot-env.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c index 111905189341..befbab156cda 100644 --- a/drivers/nvmem/u-boot-env.c +++ b/drivers/nvmem/u-boot-env.c @@ -132,6 +132,7 @@ static int u_boot_env_parse(struct u_boot_env *priv) size_t crc32_data_offset; size_t crc32_data_len; size_t crc32_offset; + __le32 *crc32_addr; size_t data_offset; size_t data_len; size_t dev_size; @@ -143,7 +144,7 @@ static int u_boot_env_parse(struct u_boot_env *priv) dev_size = nvmem_dev_size(nvmem); - buf = kcalloc(1, dev_size, GFP_KERNEL); + buf = kzalloc(dev_size, GFP_KERNEL); if (!buf) { err = -ENOMEM; goto err_out; @@ -175,7 +176,8 @@ static int u_boot_env_parse(struct u_boot_env *priv) data_offset = offsetof(struct u_boot_env_image_broadcom, data); break; } - crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset)); + crc32_addr = (__le32 *)(buf + crc32_offset); + crc32 = le32_to_cpu(*crc32_addr); crc32_data_len = dev_size - crc32_data_offset; data_len = dev_size - data_offset; @@ -188,8 +190,6 @@ static int u_boot_env_parse(struct u_boot_env *priv) buf[dev_size - 1] = '\0'; err = u_boot_env_add_cells(priv, buf, data_offset, data_len); - if (err) - dev_err(dev, "Failed to add cells: %d\n", err); err_kfree: kfree(buf);