From patchwork Sun Nov 18 20:18:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 999545 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ResaqpbD"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="nwxQgRDJ"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42yjwp4GTTz9s3Z for ; Mon, 19 Nov 2018 07:19:05 +1100 (AEDT) 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=0vegzuCL9WaSPCr4um/N8Y+r4aMus+hUiF1iNNq3fXg=; b=Res aqpbDWzX/eqCT+4Qu6Gx2XgN8tFP+rHmuQv+wapgTpoc3ZaZAJ0rY88a5iUSRP7wcDPWjkp+Gwqr6 i/vsuqVYbkWeVStON4L4loqp6SrIV07Bg8dG+aoC4BUxfG8PNGfbgUJ8x/DYUftUzALt+OUaG4lOO QdjiUrAw3EYJ30tQGZWmToGxij9THAxoBiTuHLcO8G7y0vl9qO8F1QFTYcuv7MOmrpy2OxJOHUVpR vM/PaVCbk0gIBykivJL0TNwoTfs5S/lIoMObomuLKU5SxLL/XLi6HKMAhihKT/rpxsmakq7emrJCr FNrz9hR6uZtRyGiplhGBN2JT3Le0lGw==; 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 1gOTX2-0005LX-1N; Sun, 18 Nov 2018 20:19:00 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gOTX0-0005LE-S8 for linux-mtd@bombadil.infradead.org; Sun, 18 Nov 2018 20:18:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=FD3d+nmm55NxNYbyJAXWMm5ZV44ug7VK0FSIrEc8Q6w=; b=nwxQgRDJvjAIwlfUAB1KMhVbl r7AT+w1jeUj3EbuNorNw8MGCvVJoW6y6GXx5ZKE1iliQo5mxqCseg5Z9UN4DNeU3hYHaB/ZNne9Sa jqdX9dfC6HYd6nU6UXqoB7qbORzIePzOJnv8Gvc4oQbJUVBW2hmt2fYz44Hp79BI8SnvDIN5NuqUE sw45vN4Cpx6cq1wOW5QmkU4YQqXAya0uKYXpPLVZ2HRYJAmrdWjrG8pSvfe3842pQuqn930GbeFvA MadmDOLKQEXag/wJlTgXgYWrB49MweSWLsC5Gil7Hkp8/6oA2DptUJNxMRCnAoSko85d7brkWg77V erBdNtWdg==; Received: from mail.bootlin.com ([62.4.15.54]) by casper.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gOTWw-0002sj-0A for linux-mtd@lists.infradead.org; Sun, 18 Nov 2018 20:18:56 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 6818120CFD; Sun, 18 Nov 2018 21:18:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.2 Received: from xps13.enseeiht.fr (unknown [91.224.148.103]) by mail.bootlin.com (Postfix) with ESMTPSA id EEC2A20510; Sun, 18 Nov 2018 21:18:32 +0100 (CET) From: Miquel Raynal To: Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut Subject: [PATCH 1/2] mtd: fix mtd_oobavail() incoherent returned value Date: Sun, 18 Nov 2018 21:18:30 +0100 Message-Id: <20181118201831.11636-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181118_201854_064148_DF84335B X-CRM114-Status: GOOD ( 12.37 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mtd@lists.infradead.org, Miquel Raynal MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org mtd_oobavail() returns either mtd->oovabail or mtd->oobsize. Both values are unsigned 32-bit entities, so there is no reason to pretend returning a signed one. Signed-off-by: Miquel Raynal --- include/linux/mtd/mtd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index cd0be91bdefa..035d641e8847 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -386,7 +386,7 @@ static inline struct device_node *mtd_get_of_node(struct mtd_info *mtd) return dev_of_node(&mtd->dev); } -static inline int mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops) +static inline u32 mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops) { return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize; } From patchwork Sun Nov 18 20:18:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 999546 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="EA/zEcNP"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="LsPkoAAR"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42yjwy0b52z9s3Z for ; Mon, 19 Nov 2018 07:19:13 +1100 (AEDT) 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:References: In-Reply-To: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:List-Owner; bh=gZf/Q4KOj6J5LhakV2Wcx8V1d27pcCzHupCHEeV8WHA=; b=EA/zEcNP2WduGHUMVI1Dx7e8rb 6Kpo8SMrxJbZPMUHAMuasu+Pks8pwm5UDu+qxR2RHdEOqgHoUKGFMz4qwI/3GOwHLktbDqqi2eoOB sZnuXiSIpD0bUYq3yZiFPEwa3u97KX5QSbJB+S7tOrF8cMDlm1IyhZPDi6otKws7RaT74Wf2LUdbh +KwXxXXaSuvS9IM8+vU1z1pkEi4koKiJS6J0vlPFDatoQr6bU47k0SBvAAUE7x5T6KgM7kPzal0fq vrVjem4bHdw2sDw9yQR8mbto5a3CviB8lUHuL1DaERhOTAr97TaW+8cuuzwYT18+u1U1wAV3MKDdR MoxGuWCA==; 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 1gOTX7-0005Rv-Hg; Sun, 18 Nov 2018 20:19:05 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gOTX3-0005LW-0M for linux-mtd@bombadil.infradead.org; Sun, 18 Nov 2018 20:19:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=KcCv+5/ASTf/5x1hga39cfRiYdt5FVXIC+mH0cWUWt8=; b=LsPkoAARi8p1vTY5DQt90QsGh sm8tXM20vJq0JvTV4YVvlox0N8m43cMMP3CSOJ4NOVflYbS3mx8lyIoGIhHAYcNFvVwz03ymhRw35 K62qvBOH7opFET37f7y0tAeMGP8g3MvU74f/1uvVE1XmcDSldw8Oj9xmPovt9ko3fFYWWUOcQ4qlG GYl0foadZ1GLhz4A9FHZELNsTcDAbJVmsY6N2wxAHncqpMQRoSlAD+FLvJbtPqPRP9ChYN8bXP+U7 PGyZvCFYaTEsrXyJ1g4ue3yFr79LmcEwwMJzi3zhxmYZ5lqePVpYpy/w/s8gWI8JRhPKj52iR22GB ej7sdD+Jg==; Received: from mail.bootlin.com ([62.4.15.54]) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gOTWz-0001vJ-Uq for linux-mtd@lists.infradead.org; Sun, 18 Nov 2018 20:18:58 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 6E195207B0; Sun, 18 Nov 2018 21:18:44 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.2 Received: from xps13.enseeiht.fr (unknown [91.224.148.103]) by mail.bootlin.com (Postfix) with ESMTPSA id F228B206D8; Sun, 18 Nov 2018 21:18:33 +0100 (CET) From: Miquel Raynal To: Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut Subject: [PATCH 2/2] mtd: fix Coverity integer handling issue Date: Sun, 18 Nov 2018 21:18:31 +0100 Message-Id: <20181118201831.11636-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181118201831.11636-1-miquel.raynal@bootlin.com> References: <20181118201831.11636-1-miquel.raynal@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181118_151858_128632_B3B3B13C X-CRM114-Status: GOOD ( 11.45 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on merlin.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mtd@lists.infradead.org, Miquel Raynal MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org A Coverity robot reported an integer handling issue (OVERFLOW_BEFORE_WIDEN) in the potentially overflowing expression: (mtd_div_by_ws(mtd->size, mtd) - mtd_div_by_ws(offs, mtd)) * mtd_oobavail(mtd, ops) While such overflow will certainly never happen due to the numbers handled, it is cleaner to fix this operation anyway. The problem is that all the maths include 32-bit quantities, while the result is stored in an explicit 64-bit value. As maxooblen will just be compared with a size_t, let's change the type of the variable to a size_t. This will not fix anything but will clarify a bit the situation. Then, do an explicit cast to fix Coverity warning. Signed-off-by: Miquel Raynal --- drivers/mtd/mtdcore.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 97ac219c082e..afb4b17fb670 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -1136,13 +1136,13 @@ static int mtd_check_oob_ops(struct mtd_info *mtd, loff_t offs, return -EINVAL; if (ops->ooblen) { - u64 maxooblen; + size_t maxooblen; if (ops->ooboffs >= mtd_oobavail(mtd, ops)) return -EINVAL; - maxooblen = ((mtd_div_by_ws(mtd->size, mtd) - - mtd_div_by_ws(offs, mtd)) * + maxooblen = ((size_t)(mtd_div_by_ws(mtd->size, mtd) - + mtd_div_by_ws(offs, mtd)) * mtd_oobavail(mtd, ops)) - ops->ooboffs; if (ops->ooblen > maxooblen) return -EINVAL;