From patchwork Wed Jun 5 16:40:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Michael_B=C3=BCsch?= X-Patchwork-Id: 10977361 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 AC32314B6 for ; Wed, 5 Jun 2019 17:01:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A95B289D2 for ; Wed, 5 Jun 2019 17:01:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E2BB28A6A; Wed, 5 Jun 2019 17:01:45 +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=-6.9 required=2.0 tests=BAYES_00,FROM_EXCESS_BASE64, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCD72286DF for ; Wed, 5 Jun 2019 17:01:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728809AbfFERBo (ORCPT ); Wed, 5 Jun 2019 13:01:44 -0400 Received: from bues.ch ([80.190.117.144]:48902 "EHLO bues.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728774AbfFERBo (ORCPT ); Wed, 5 Jun 2019 13:01:44 -0400 X-Greylist: delayed 1139 seconds by postgrey-1.27 at vger.kernel.org; Wed, 05 Jun 2019 13:01:43 EDT Received: by bues.ch with esmtpsa (Exim 4.89) (envelope-from ) id 1hYYzq-00073t-A7; Wed, 05 Jun 2019 18:42:42 +0200 Date: Wed, 5 Jun 2019 18:40:45 +0200 From: Michael =?utf-8?b?QsO8c2No?= To: Mark Brown Cc: linux-spi@vger.kernel.org Subject: [PATCH] spi-bcm2835: Always initialize local variable in bcm2835_wr_fifo_count Message-ID: <20190605184045.5ce33d92@wiggum> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If count is less than 4 and memcpy copies less than 4 bytes into var, some bytes remain uninitialized. These uninitialized bytes are taken from var and written to the BCM2835_SPI_FIFO register. While the hardware probably is able to ignore these extra bytes, it's Undefined Behavior to read uninitialized bytes. So don't do that. Signed-off-by: Michael Buesch Cc: stable@vger.kernel.org --- drivers/spi/spi-bcm2835.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index 9c03da7c18dd..5b0119cc2b07 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -253,12 +253,11 @@ static inline void bcm2835_wr_fifo_count(struct bcm2835_spi *bs, int count) bs->tx_len -= count; while (count > 0) { + val = 0; if (bs->tx_buf) { len = min(count, 4); memcpy(&val, bs->tx_buf, len); bs->tx_buf += len; - } else { - val = 0; } bcm2835_wr(bs, BCM2835_SPI_FIFO, val); count -= 4;