From patchwork Sat Jul 27 19:34:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 11062659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A4C4746 for ; Sat, 27 Jul 2019 19:34:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3ECBF289DC for ; Sat, 27 Jul 2019 19:34:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F01028A16; Sat, 27 Jul 2019 19:34:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C91DD289DC for ; Sat, 27 Jul 2019 19:34:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=sBlKxbxF3VFoLNdv/Omsu0gvPhtJq26+/rV/fzwX/Bw=; b=P7e9ZnwJ3tNIDN 0C3GbNIN4pdmZqWDs8cHxk4yH3pELNVDJrCTBW4bsRP5iN4Q6fldn0M57hx7NVfxldUyE60B9984E Mi7fY6W6/iYdK6lghj9tr8xKRfQIBznxrd4ZCf1gyvdL8gjvTclg7mwmM/HYGW2fnI4Qqc79huNYZ 6y2u9yvICycbhdkotQEzh2OlLdXNi0YLqa7NVHuj3nfF4IikjfEzH+fNQ3OsSRjUA+pIRQ+Ld5KdA tgoAasJ0vasQ8ExsEfUGaWn+kkqdkDGtNUQkBJCzODKYBt4DObaL+o5xZ1tzPn2RdMrZ1J+wJ+t2F 4cv8PeaL8VMu0BxgBGvQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hrSSj-0004KV-3t; Sat, 27 Jul 2019 19:34:37 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hrSSh-0004Jo-23; Sat, 27 Jul 2019 19:34:36 +0000 Received: by mail-wr1-x441.google.com with SMTP id n4so57766148wrs.3; Sat, 27 Jul 2019 12:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CwPC0uC2vhnnQFt6dtjfct0lT1hDdrq7y6oBUVdLJKw=; b=QHT+vr7UctQsq5De/q5TWMQcuzSpL9ljxuV/hNLT+ItJwKXkM5g0LOvOUd02ezmEgN I9oEh9513WE73nzCZyW2keHtEuqZpwwDcSya5rATKTtZS58nE2Qe7BZLO6CzOpQGeoMO t63VYywAg5wGh+gDQPQixN/ocPo44KmMqJ7gyBLUeZIkhBUXCOAcfweN9A9U2uyNKkjt j2MGWuCFgqB2fu9j+oN2xm0rTzmMou7027hLuHn/CDTIiL777gOwV9l2CxAm78GnV6L4 sW4AlzaBnvgMuiJoSEAkZxefKDwMqv1nMl1oJ8HGWMjelXlyk0MGOZOr2umlEIcQUbY5 adrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CwPC0uC2vhnnQFt6dtjfct0lT1hDdrq7y6oBUVdLJKw=; b=hBAM9tXw3hE6OoIo6WBdmmVOZ5lfDlKuynz9ckPjcTvZnCHHyLC41KVswoswEAu8yC 4VshPz64uv/CIEOlAycOeVtoiYWNfkzBRw7U8N2tv1DJxIXWql+MC7/2qbMtD2Daw/6Y 7H3JQ7YPGNWaJWSKMT6FEQr/2IXt2104QrlO0ojAYIPP7bLKypfHP2aQJgdSJwsRpEjl ZaLEqYEQYg9Y0+eX3daygwYbw9rtAFGU0Q8eLJKUnbxNAK1+PXkpwEiARyKQhpr9png9 QnVZ/jYoqc4BOsx5ljDRk/croT1RnXnO3xCiVUuGNQ1LFbQztqxhxPkhUn4IBvRbB0/D 0khg== X-Gm-Message-State: APjAAAXeN7nx1K/g+NDTtSp8e4aYKLeb6r6jfLPtc76eEjjsj8qKdPOA 5Wog6S+91dGRIXXwvVRMWrzqTYEq X-Google-Smtp-Source: APXvYqwtcykN6reCHIDCRtC2TmW13zB5ZF0C7B4/4u2+Ho0Ih/KuuXH6Lj6HdkYgFIebULYKFdTG9Q== X-Received: by 2002:a5d:668e:: with SMTP id l14mr52098236wru.156.1564256073191; Sat, 27 Jul 2019 12:34:33 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133C65C00B418D0F4A25A19EC.dip0.t-ipconnect.de. [2003:f1:33c6:5c00:b418:d0f4:a25a:19ec]) by smtp.googlemail.com with ESMTPSA id n3sm50301258wrt.31.2019.07.27.12.34.32 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 27 Jul 2019 12:34:32 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, srinivas.kandagatla@linaro.org Subject: [PATCH v2] nvmem: meson-mx-efuse: allow reading data smaller than word_size Date: Sat, 27 Jul 2019 21:34:14 +0200 Message-Id: <20190727193414.11371-1-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190727_123435_095810_5928A4D9 X-CRM114-Status: GOOD ( 10.58 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Some Amlogic boards store the Ethernet MAC address inside the eFuse. The Ethernet MAC address uses 6 bytes. The existing logic in meson_mx_efuse_read() would write beyond the end of the data buffer when trying to read data with a size that is not aligned to word_size (4 bytes on Meson8, Meson8b and Meson8m2). Calculate the remaining data to copy inside meson_mx_efuse_read() so reading 6 bytes doesn't write beyond the end of the data buffer. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- Changes since v1: - switch from min() to min_t() to get rid of a compiler warning drivers/nvmem/meson-mx-efuse.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/meson-mx-efuse.c b/drivers/nvmem/meson-mx-efuse.c index 2976aef87c82..e8fc0baa09e7 100644 --- a/drivers/nvmem/meson-mx-efuse.c +++ b/drivers/nvmem/meson-mx-efuse.c @@ -155,7 +155,8 @@ static int meson_mx_efuse_read(void *context, unsigned int offset, if (err) break; - memcpy(buf + i, &tmp, efuse->config.word_size); + memcpy(buf + i, &tmp, + min_t(size_t, bytes - i, efuse->config.word_size)); } meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1,