From patchwork Fri Feb 15 09:02:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 10814391 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 9639613A4 for ; Fri, 15 Feb 2019 09:02:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39FEE29C9A for ; Fri, 15 Feb 2019 09:02:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E23B2DBD2; Fri, 15 Feb 2019 09:02:22 +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_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable 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 DABCA29D6E for ; Fri, 15 Feb 2019 09:02:21 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=EbVOyl62XVESnbhP4bbdAWQWc8uzx39RQPEUQt8ljmg=; b=bkA SqtFUSFRt7VJsBz245zNlI1lI5zZv+H1nL09YW8BfKymohWHExAf2x+NcZ0cnQ2g2/7y0JGzQTo8L FY+2s041E7/Hn837ThwCqdZULmKedmenExb64NwXzxSQAYTf6TWXQggMxt9TrYp1u9bUxDTxqYaTt gozRCgMZ/yFnpXzo8Qbdm+vkwy+KKryqcMVDvaGNKWp5POFJDvTEz1nhROwXra4k5GCKhSmanhZE5 aDDIAqHHROi24xXfnzfBt8zf+XSkoC5eG9jrrqdx3XHtrVAwl0OsbSamaid7+ymyAfSLDAj7aieRm C8H3RVob4yqSJUxaQxneTUSRQ/TqC6w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1guZO1-0002gW-4d; Fri, 15 Feb 2019 09:02:21 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1guZNr-0002RD-TE for linux-mediatek@lists.infradead.org; Fri, 15 Feb 2019 09:02:14 +0000 Received: by mail-pf1-x441.google.com with SMTP id g6so4520354pfh.13 for ; Fri, 15 Feb 2019 01:02:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=TKEr6BQfPYwpZOOmXDLLiGCXvoI2GmC6CPcG6Delj7k=; b=M06tQnzmpEvPURrsn18wmE1G0bf8j/j3E4/gaRn5UHdWAIszU5S/8BRF4bn0GNtXSe r7t1bSEpPbePPUAaBWw95Kui9EIi7UJTA81Di6i6f5bxLCXBdflLoBmKbdqrWgc+DwRL gE2EemCnKz5LtwY05osXbp7gG2eB8OesL0+Ec= 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; bh=TKEr6BQfPYwpZOOmXDLLiGCXvoI2GmC6CPcG6Delj7k=; b=MwIVlTxMWQfZGL1ZKI6N58ytPB4TR7YDu6ZOHOUD4pFZGkECWGD2R4fPiiUA6m+I8O AH5z2ottHSaXJeTgfBtHJ+D7KdLXPMbscQCVvj/JuJRHbdyoVBJeIv7DLO1piTgJAgLW NrfN7jhrm+v9MVCCorlr4udM6Mb+FV954yi04KhmGPNsq0UA2snzi9urbEJneHSnRUYJ EFGgWHPGTTrDY/BL67VyOHi9ovfrQhFXUHk6WFGdWxQ30vlHc5P7ykwYpcdV93OARPpX 2ERpNUaTjphb+e+IhcjErMLfEToYp1g/z6XVn5XxzUKXcr5pUzU0HCOvB9CTpf8PXRjb kCKQ== X-Gm-Message-State: AHQUAub/pIHRc3w1/6HMn7Vo+TSy+wZT21X5IdBf51PS+y/W21ukGm0x T1fo6jXzgcdiBKc6FPtglqhgOQ== X-Google-Smtp-Source: AHgI3IZ+IPALVVKhe1XQ2ry7m3Jzss69II/WcqBU5mzDNdUy2gIbEPcfg4GYGt2NpDsJktpgvm9zaw== X-Received: by 2002:a65:6219:: with SMTP id d25mr4392407pgv.18.1550221330954; Fri, 15 Feb 2019 01:02:10 -0800 (PST) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:b852:bd51:9305:4261]) by smtp.gmail.com with ESMTPSA id z67sm9012653pfd.188.2019.02.15.01.02.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Feb 2019 01:02:10 -0800 (PST) From: Hsin-Yi Wang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] i2c: mediatek: modify threshold passed to i2c_get_dma_safe_msg_buf() Date: Fri, 15 Feb 2019 17:02:02 +0800 Message-Id: <20190215090202.157100-1-hsinyi@chromium.org> X-Mailer: git-send-email 2.18.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190215_010211_966043_21B43FDC X-CRM114-Status: GOOD ( 10.49 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ryder Lee , Wolfram Sang , Jun Gao , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-i2c@vger.kernel.org, Hsin-Yi Wang , Matthias Brugger MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP i2c_get_dma_safe_msg_buf() allocates space based on msg->len. If threshold is 0 and msg->len is also 0, function makes zero-length allocation, which returns a special ZERO_SIZE_PTR instead of a NULL pointer, and this will cause later code to fail. Modify the threshold to > 0 so the function returns NULL pointer. Fixes: fc66b39fe36a ("i2c: mediatek: Use DMA safe buffers for i2c transactions") Signed-off-by: Hsin-Yi Wang --- drivers/i2c/busses/i2c-mt65xx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c index a74ef76705e0..2bb4d20ead32 100644 --- a/drivers/i2c/busses/i2c-mt65xx.c +++ b/drivers/i2c/busses/i2c-mt65xx.c @@ -503,7 +503,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG); writel(I2C_DMA_CON_RX, i2c->pdmabase + OFFSET_CON); - dma_rd_buf = i2c_get_dma_safe_msg_buf(msgs, 0); + dma_rd_buf = i2c_get_dma_safe_msg_buf(msgs, 1); if (!dma_rd_buf) return -ENOMEM; @@ -526,7 +526,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, writel(I2C_DMA_INT_FLAG_NONE, i2c->pdmabase + OFFSET_INT_FLAG); writel(I2C_DMA_CON_TX, i2c->pdmabase + OFFSET_CON); - dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 0); + dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 1); if (!dma_wr_buf) return -ENOMEM; @@ -549,7 +549,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_INT_FLAG); writel(I2C_DMA_CLR_FLAG, i2c->pdmabase + OFFSET_CON); - dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 0); + dma_wr_buf = i2c_get_dma_safe_msg_buf(msgs, 1); if (!dma_wr_buf) return -ENOMEM; @@ -561,7 +561,7 @@ static int mtk_i2c_do_transfer(struct mtk_i2c *i2c, struct i2c_msg *msgs, return -ENOMEM; } - dma_rd_buf = i2c_get_dma_safe_msg_buf((msgs + 1), 0); + dma_rd_buf = i2c_get_dma_safe_msg_buf((msgs + 1), 1); if (!dma_rd_buf) { dma_unmap_single(i2c->dev, wpaddr, msgs->len, DMA_TO_DEVICE);