From patchwork Thu Dec 21 17:34:20 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: 13502451 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 86762C46CD2 for ; Thu, 21 Dec 2023 17:35:37 +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=LZYjo35IcHGeLTAw3d80MWzvemfufmUVu9hcL7CvZx8=; b=cJ2tBSzM+C6SKH 2jR8mK/GWiNZrr34PAie2MxBvNXOT4NlsCdsMIH5Nngn1F1e4EpxNA9mI/l/vG8K/b/kzZRL7/Nb+ s0DonIuDMXVofLCcRNlw9tyHdqr6ZvxTW0llDLGWwA3RHOMsZqhGi4uUsPzROeZ7lPLM11es35/jh 1WI3HRelRJfxeVfjYX9ONswyA+XoL+FtNJPFJJQ27eGwGIbkG2mXkmSEUm68I86LW+f0HSPLbEgGA 8g64qqHveBNrjtEGedY1CmeKHy5C8j3U7yjMPHlzD2uX5CMSEQ7qDcB4oX8Vh5d8bvja93hQlGLW3 OgXtq/HGBftTza8ruC5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rGMwx-003gQq-29; Thu, 21 Dec 2023 17:35:11 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rGMwV-003g3d-3A; Thu, 21 Dec 2023 17:34:45 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a2371eae8f1so123908066b.1; Thu, 21 Dec 2023 09:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703180080; x=1703784880; 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=1XhPv1RG5GYBxA6YK5orD14R9QXHs06Ax0C4Bquly6M=; b=cDztAuJvoKoGkYWu73aPmJbAceg8T9k0QPWoTksEnkC8kmUmtqcffVcwmBIW44oQ4x t0WKkcNhnXxvW0ufYevULQ0jiXqAJ0Q7fzBuxtL5WP+bBTlAyD+Tj0Cil/5RZlwn8QhN voCmVdG3FotxjIFw16jszIYeUG5Dxay1wo0UV3AUl4KsANBThg12toJfAkkyDil8ZlIU Pn+aGn6YotvwbJ7q1r9cJbkq62hnMFkUTux6RQA08U2BMKzZAgHT4nyiqHfrBqAV2Vju 2jlsYtOSbg7IXUM7mMlVPrpsgYayBm7nCKGGsucorSd781aCLxM76bQP375SfoqatX1l /pmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703180080; x=1703784880; 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=1XhPv1RG5GYBxA6YK5orD14R9QXHs06Ax0C4Bquly6M=; b=XpdcztVUG9A8rVm6RnYfVoB7Z7ixnWw0PY2jxLvRtPfCDRlLaP2R8D0KC2yNDALqJy FkLIEjjjPBKRJXd6ZzM8VTJw5BOa3SYah2KWtbRtdtcxLJMhb8gPS5z4j0GHDFD79PFA A2zavz/xlQ9i2Oy48nidelNihODHEdsbfqnSWZfFyoqz4myAhtkjqaSfMcL1uI0JJQ8j d2ZaCtd8cdwKlMg+dnUXIwOhP/Gpubr3vS6KK4hvR605mZETWJXdjgbbAgbDZ5iS9Xzd u619TJE0aHSNxD+MDWZ0H9IGgtQjso1b5Okaxs7jpgXBY/YaZliPjWM9mcseF0VvfuTs 5ySQ== X-Gm-Message-State: AOJu0Yy7O5Tg204iZXSGp9E1ERggGMdMecw/iNz587YY/4ZNW9JONC+x sN4EXTPnPSjYRi+oklhwe+A= X-Google-Smtp-Source: AGHT+IEY+7wyVZIZ+h3uGtQYr+kF581gR4pDcml555wj8gHDXaLod5c5pIXzSSoJp59GcB1hlVt2Ww== X-Received: by 2002:a17:906:3c18:b0:a22:e2ea:4fad with SMTP id h24-20020a1709063c1800b00a22e2ea4fadmr83814ejg.83.1703180079840; Thu, 21 Dec 2023 09:34:39 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 09:34:39 -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 5/6] nvmem: u-boot-env: improve coding style Date: Thu, 21 Dec 2023 18:34:20 +0100 Message-Id: <20231221173421.13737-5-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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231221_093444_026766_06B6E764 X-CRM114-Status: GOOD ( 12.91 ) 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);