From patchwork Thu Feb 28 14:22:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorge Ramirez-Ortiz X-Patchwork-Id: 159377 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp699290jad; Thu, 28 Feb 2019 06:22:15 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ0XSR7tZS43BuD16ry1FAIlDW1ai5/k70cLbJP00gQOvGIOg5Kb6Tj3g1+UZ/87iMVQFSx X-Received: by 2002:a17:902:b591:: with SMTP id a17mr8439466pls.228.1551363735366; Thu, 28 Feb 2019 06:22:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551363735; cv=none; d=google.com; s=arc-20160816; b=WcqK//mezjKoDe5wSd+tIl0bY+SmnwvPauh7Y1rMwWd9wkvmrIku1uTo14T8Y4Wt33 wlC+KZEGkK/4ZIJpTntzIEaCiNGTSbNCwrUt90UFl44kXJCuNdWUvw8fZJHpHmXEdRMo XOS+N+66ghlSLwAEY0z7rlZWD4ltfhzitxttP8YL92cZqQDNiKa0V3kEaLjD2jN9p1u4 ouoB/spL8rZKgH11nPtd6ehbisa3cFktqszKWF1Yyn/mvmuNlLmM+4WCnEUGYBu97tld DR4HZCBNVgX3ru0PxQ0KMbVlVaXuqQiaZRxPfCTG9x3ipJbHKS3jyVzEf2Pm+f2487hh mPig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9N+9t9ja6hje8oSOcYPUEt2SpVLCg1jRZ/xYyjM4aPM=; b=BD7iwq8FN45a4R5gmbZco7gYqHQ6rhPuFE/4H4iMwUl3tddgTxNvpV2QNYz9QKplzd zMYK9OSX8VXzyh3CJU0E2HSmpc4v0zM3W2Y60n2hZLWfLKZXJiPQ5Ittgv0PRkOBZIjx eCF/OmZ9qf6kWzz2V6rolROlQOhE/g5+LEktr6WFO7lc+TT6g5hOFHxCNBj8RldFoFKk 3ZcK2qYsiQw2Ka8QkFzz04CxuNshErSbpPAbgHVdo7mENPKfUmBeCnih0mXttDV34NIS n+qFyPVfi64uhhF/meF5YJvktSVLzod+0VWora3ayHe4PE2gh00S6XJuKNchpIOOmxMu 8rSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xOSerX4n; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6si17598250plo.129.2019.02.28.06.22.15; Thu, 28 Feb 2019 06:22:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xOSerX4n; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732083AbfB1OWK (ORCPT + 31 others); Thu, 28 Feb 2019 09:22:10 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42282 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726101AbfB1OWK (ORCPT ); Thu, 28 Feb 2019 09:22:10 -0500 Received: by mail-wr1-f65.google.com with SMTP id r5so22137098wrg.9 for ; Thu, 28 Feb 2019 06:22:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9N+9t9ja6hje8oSOcYPUEt2SpVLCg1jRZ/xYyjM4aPM=; b=xOSerX4nxxIpRfSA3tFlpKtgLbMPzeVH7ivxnF8DPpPKVIv26aB78jRlZO8t83RJIW iL+iualMYmx3Hqs9UcdpAyu1r0gVBFKU3R9uEX0z86XLqH2Evg3gjOPWXqZX/gFdg851 3jCmQRbRrbtZEj5hfoEvLAliRl0o/QIO4VXPOmvi/zGvofwxrRAEp1JpvfQgET2dxHZT IDxacSPEGZPUMtenKXl4D7gJmAZaJWYfe8HJrI/WsKUsehPZskiK5AXa/xqiOOrg/KnY 8KtKaS0IwUeqAglp/lfPGnc+Hb3rKSUdkqXcF5d30fvK41Qsb+3l2QGG6MNxPT4EoZVq MD1Q== 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=9N+9t9ja6hje8oSOcYPUEt2SpVLCg1jRZ/xYyjM4aPM=; b=OZv0SfV5XS/I57XU2fIiXGQijVXRWP6i+maBcakSdLIhHwCtSs8qx9xprrzxMJd3H+ /ZV/MhwKRjggg58nk//RnR6P6xqikzeDUL/eGBVzGndNrn6xDTikQHJFSzDOJBoy+qvk 3gw/vNRo0oHcX4l2E+zM1RHeBdn4oiaMQb8vuJPRKq+Pquuz2kzhvScy6UJobbsXQyPw TU8NANwtYttxmeOkOuPhF34UUY7TAi/SJuTHLYTxqv1JaS8oPtyBOryhPJfw7ySg1nTJ Ba/myIxOHhptHp1fuT12PXNBa28O7mEnxIfeqqSb4Rqs1GAEOn5MZ902bRHrc4bQfc1P 4Y5A== X-Gm-Message-State: APjAAAWUIClEL3MJfNdoG9LZuIA6xqaOmIxJ2RDHuwzTekF8Qcvzcgxn SrNv/NABhNyih2iFz6YV0CuGlfzJU1E= X-Received: by 2002:a05:6000:10c9:: with SMTP id b9mr6433914wrx.281.1551363728555; Thu, 28 Feb 2019 06:22:08 -0800 (PST) Received: from localhost.localdomain (45.red-83-34-201.dynamicip.rima-tde.net. [83.34.201.45]) by smtp.gmail.com with ESMTPSA id d15sm38783652wrw.36.2019.02.28.06.22.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Feb 2019 06:22:07 -0800 (PST) From: Jorge Ramirez-Ortiz To: jorge.ramirez-ortiz@linaro.org, srinivas.kandagatla@linaro.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] nvmem: core: fix read_buffer in place Date: Thu, 28 Feb 2019 15:22:04 +0100 Message-Id: <20190228142204.9873-1-jorge.ramirez-ortiz@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org All unused/extra bytes in the cell buffer must be zeroed. Signed-off-by: Jorge Ramirez-Ortiz --- drivers/nvmem/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index f7301bb4ef3b..65e198adebac 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1162,7 +1162,7 @@ EXPORT_SYMBOL_GPL(nvmem_cell_put); static void nvmem_shift_read_buffer_in_place(struct nvmem_cell *cell, void *buf) { u8 *p, *b; - int i, bit_offset = cell->bit_offset; + int i, extra, bit_offset = cell->bit_offset; p = b = buf; if (bit_offset) { @@ -1179,7 +1179,8 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell *cell, void *buf) } /* result fits in less bytes */ - if (cell->bytes != DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE)) + extra = cell->bytes - DIV_ROUND_UP(cell->nbits, BITS_PER_BYTE); + while (--extra >= 0) *p-- = 0; } /* clear msb bits if any leftover in the last byte */