From patchwork Sat Jul 27 19:19:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 11062653 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 1797F746 for ; Sat, 27 Jul 2019 19:20:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BEC5287CC for ; Sat, 27 Jul 2019 19:20:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 101312899B; Sat, 27 Jul 2019 19:20:18 +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 B92C1287CC for ; Sat, 27 Jul 2019 19:20:17 +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=C/l7KRc1Ccw/2NrjBYINL9d4QNxnNrHRrrOnPgyeYKo=; b=MCSpBwBLtPPR3H 8cibbVDrQSxVsjhGTduwJPOron/1Z5RtdA1co40cCLyTGHUg/lPT+/2Mw81IAYw0btUumAxRHryRI cyZvK8hUse6r3bEIFtMMfpR9PB2n7D/ZdCcdE/ooiwNHh6UB0YrdLlWdew0AqMHkTUnxyhDuyHdeM 0hqS0Amhmcm0IBqLvyzYaDMQc7K71oPgbGxn8nx96xtpeOFRi5bLtvAJ+m7ftdhRB3+PJyA+djvjJ nVZ5GLQJxza5IiRR4rS4e5CcCeAKpVfyFJ4jjsh5JHEGLL7ogz75VZIhasm4Zy2VpKvY1wPbuL/5B gIw8bPwTOMVH5yRL0KmA==; 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 1hrSEq-0000PZ-EO; Sat, 27 Jul 2019 19:20:16 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hrSEm-0000Nf-CX; Sat, 27 Jul 2019 19:20:13 +0000 Received: by mail-wm1-x343.google.com with SMTP id 207so50558616wma.1; Sat, 27 Jul 2019 12:20:11 -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=h4n2rUT6ZGdvoy/BsktvZgyBHxTE8rabTOOnA69x0k8=; b=oQsq/To7J5ogzOa0TSjkybKTMPS3rtaiNVWREDB3u4pj4MaZ7uneyrh5zmved/Gntk gLlWhpYQ8qveg6e+khO+Q8L0L8buTannUuOs0zyD/dNw8891kufDYrJMD1SH4Ca/6EkO 9bkTW8xa2yrodLmVWGiJMQH6V7EBjWTzPu0SoeSnFXzH9+C2VbfXumyVgSgEzXBTU+ME FfqTxYedHGWQRdA+aPa8Xfh6cdzseXvGgksOCz9d2mBKvb6d43wjCW5MfqQT4LjfsblU RhY8+CLcDC6+/mhIU0KI+m0SXawZdENqWoy/ofH/7/4QdWLmUOhI1/9gdoIg06vsJw6Y Jxmw== 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=h4n2rUT6ZGdvoy/BsktvZgyBHxTE8rabTOOnA69x0k8=; b=rKfkY+QEIrQdMMLyRYhR5bSpl0cDqBcKz6KWexYQ8Pkm8JlA7YneeVFInudruzhZL9 zwMhI02QasHU+ngGEi8ii7IhKBNJN7GeTVwrf9e+M+uQuLvpdxsmJCLXXaFBp27/ftSb /IZv5Z7/fLdDRbTuK5jfGFdA4osZ48gqFEl4UHXe05zWSQenv6n2Ps3jf0lL338Kc0l5 yzbMLU3dSV4fANeu+aDgPSFXGBpZKsEOqzleGhgUC9vJLoAmvb0JbuM9WkBWt4YNPE8n mMg+LhS+lXVKLB0hGW82TOS9/c8AdQDjD5m+OW7a9ldiGepdUTfRA88xfHpVdBxbfe9C peJw== X-Gm-Message-State: APjAAAWqWwEDQFH/NWMUcBxgPc+YpI37b94ZHXdVnIO/xo06g2VzmpeG jXV/1GbkLVEifYba5835R+0ntlY3 X-Google-Smtp-Source: APXvYqzg0efJoczgVWfrxUdgaiXSFNAa16hmUCsmIbTjaatCammoQ2y4fvocHoaMMKYHdCOH+tfyjA== X-Received: by 2002:a7b:cf0b:: with SMTP id l11mr95920292wmg.143.1564255209778; Sat, 27 Jul 2019 12:20:09 -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 e7sm51506988wmd.0.2019.07.27.12.20.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 27 Jul 2019 12:20:09 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, srinivas.kandagatla@linaro.org Subject: [PATCH] nvmem: meson-mx-efuse: allow reading data smaller than word_size Date: Sat, 27 Jul 2019 21:19:58 +0200 Message-Id: <20190727191958.27240-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_122012_452457_BF9BCA7C X-CRM114-Status: GOOD ( 10.54 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=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 --- drivers/nvmem/meson-mx-efuse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvmem/meson-mx-efuse.c b/drivers/nvmem/meson-mx-efuse.c index 2976aef87c82..d5ccde1abd8e 100644 --- a/drivers/nvmem/meson-mx-efuse.c +++ b/drivers/nvmem/meson-mx-efuse.c @@ -155,7 +155,7 @@ 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(bytes - i, efuse->config.word_size)); } meson_mx_efuse_mask_bits(efuse, MESON_MX_EFUSE_CNTL1,