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: 13498668 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 B595EC46CCD for ; Tue, 19 Dec 2023 17:41:16 +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=M/2IKMZonnqbWwQUyOGYf/zD4T8FhmIlX2QZHj0ELOo=; b=YAwrvcs7KNCzG5 sIJqwFyS53MEbPl7uhW5pJwYVAF6yasFJlzC0jrZboqxz9xn5NBf3lZmiAsWBGGlo9YJ76e2jRNEO ACMUrspnHPZW7M7bZCnZfCNBMi2COXsKVlncQfOhZStE4y9p1zilRFRBWheYGzR6xH5O9e5mLx1Yd UAziDvj56u7YzMcRMxsGt4H/ie6rvbYYey8nu4gOLXIEARUyxFAl7P/hvR7+q22WXjwjbVHhQhPwb huVKqckC1gfmq9m/8Nk9uNXmeu7wux6PSA5tHH5FTU5M1S8AXhHfNLwWIzkd7K7MoQSd4q7NfnGIw 7ueygBAl0FPfuNWT12CQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFe5N-00Eytm-2Z; Tue, 19 Dec 2023 17:40:53 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFe5G-00EypC-1S; Tue, 19 Dec 2023 17:40:47 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a235e394758so286860066b.1; 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=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=lvbpVGdOkFoSIrqGEOI2u72GgRBjNjQRomAfCiRlrrE=; b=kleIx50BmOeMFkdRVPhuxwVbi+YzsYYb7BVYSwH0HxBoi/zwaoIbvtQeAEzs9deXgP Gmjc9zYF3ousyZN1Oc2Lh3vHZce7FnFf9+Iv/K6pcEwtuhOlolRQ+0fe2CWrqLBIyaud MKPluDyiSbQ7473yrYRxGwcFnV7UBDx0sHLT7MtKLq1dSCrqTGRKPtVLpxcDM9P+6pCl CPchIVg9dxSBi1dCWclq+y53qjmbW9xl17nn4Qa8EhyHaukutkhXVRn4CdXAov7T/aBk hdJ4baFHmVoNncp+FDAR2s9CrT5gBH2ENUsSghxKF0z0WSNHNafBbFJtmHHMKxEWYYWJ /CsQ== 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=YuMf684wihmFx5xDGA/m6xqhUiQbj6Z+tqtl92vMnhMs3tJrdqv+vilB7DRF8F23kJ uUS2CG+DJtZMB04FhOo9wsixu8uW02QQ04468+1MikJ18DZMmH3DpU2tTdP+tp6vnve6 TVG/Pno8kybx8AWoDGrq+8ikyS5L6Ykg3woX1eG5zPEtmrkaoS62cnOUumvTuR4/J2gH rTsPJ7+7q+6Q34lxgcKTGCQlnk5NVe5PTK7FlrUx5o7HGyeZAShJkPjlbDDbbt85cz5U tbq3rCjJ3hMEf3JUtrlA5NSkYZebIcU4bu8I9Asag4vGZyrIxGOvmsBU+So3ZoSnd59a je0w== X-Gm-Message-State: AOJu0YwsB5uR6Dc++Ero6xXb3pt4oEc8cQ2RIRxwrEoi7eGbF+fyyLb7 FABEp2tZuhejMgdSuu65doM= X-Google-Smtp-Source: AGHT+IF7v0el0xOUJw8FCEGpmE14E0MqTBdoBv0Uaj9ZYjmK4P8W4YVF7oTGw5Pmx8ydiXStN/I61g== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231219_094046_489791_4E6073C9 X-CRM114-Status: GOOD ( 13.56 ) 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 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);