From patchwork Mon Feb 1 10:33:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101008 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2957587lbb; Mon, 1 Feb 2016 02:33:55 -0800 (PST) X-Received: by 10.98.9.92 with SMTP id e89mr5750207pfd.34.1454322835631; Mon, 01 Feb 2016 02:33:55 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q12si23476305par.45.2016.02.01.02.33.55; Mon, 01 Feb 2016 02:33:55 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753473AbcBAKdx (ORCPT + 30 others); Mon, 1 Feb 2016 05:33:53 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:50734 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752956AbcBAKdw (ORCPT ); Mon, 1 Feb 2016 05:33:52 -0500 Received: from wuerfel.localnet ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue101) with ESMTPSA (Nemesis) id 0MarfO-1af7LQ2Y7W-00KOzg; Mon, 01 Feb 2016 11:33:18 +0100 From: Arnd Bergmann To: gregkh@linuxfoundation.org Cc: Greg Hackmann , Jin Qian , Alan Cox , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] staging: goldfish: use div64_s64 instead of do_div Date: Mon, 01 Feb 2016 11:33 +0100 Message-ID: <1676170.0qik6mzm6D@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) MIME-Version: 1.0 X-Provags-ID: V03:K0:dZRSU/fbzDCb+d2lG0X9AY+r72AhAazJdtLIrt2s/mpY0xGM1Gz 3cP9Rbc4ZagvU/fDX2o2ldkEq5cEKRLApFaXi7oKyAkgJVuT5NCcZbFz4+GjhGqoi/I8mHb KBmwC3omycqiPP+E1sVBJhRQ9GkF0IYEEU2tAEa9MYKqJmt+kIiBIkFO3T1stPQRJDX9OyZ ErqzDl1uHglbVizAiReKg== X-UI-Out-Filterresults: notjunk:1; V01:K0:VahZpGEJ7/Y=:sVWFKcdprLzwWAymAqikSi j5EEon/+dCHAPkytFT6c8VG0kplkzGYBnQrcqk+siMgMsFjZKBV27IuNJoPPJp5jYjIgUgwXo 8m1Len36UgZ+aopZ37QfcI02KeXLepScROTpex44jl0L8B722J19SIsxhLHw+SUVSXm4bWeY6 jAczdH/JzSXXwn40XGXuFs3qQ5f9UsvxytwaMdIiSUErfZUmv3TA7DLXOiAroPl+XMn3J2fUp eAwaoLpPmXzqIJpGqkMJ4Zs0DTnRSDSe0tuQwjfDwO9iJYI+FUwuLqnS7g5lddKRyib3J41iy TciEgwOrUeaYek215aTWDh6/P463FaRAf5lPNHae3+HiJoLEeibL8QCipeiungiSrr83q07IO IMBfhtw3ZfPsE1e3vE9q5MVKzI4R6zEg8u+YtgfKLJivDqbsHCOqh6f+DUPNEH2gNb8fN8D4u 6JAZ+fgdqxqCLcTSHDnyMDZ+4yS1EzsU2pTIPb0a/xtUwci0+0SjlSHKhuf896S4hIs/h3pZd VGCsk4eWNADweiGigvISN3S5mugl1WIgQIlyNtF++qFvMdY7r2ubr42l3PorCBc70phguugnD 3Iv2FH9mS/9/1OLaEcyEw4Q5UZrme8egMJ+tlG/P0voShdkHBrKxFvGoAvuV1JI5HGahAvp9Z HbfO9wk3pc8xRrdExybdhbYR8GJbyBpySHxmOhnKEeqEIxoODEaDEqvQyMJO+jRGkFL7I9s8F vFdFlOiALwftWt/+ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The goldfish nand driver divides a signed 64-bit number (loff_t) in multiple places using the do_div() function. This has always been unreliable but now produces a compiler warning (since 4.5-rc1): goldfish/goldfish_nand.c: In function 'goldfish_nand_erase': goldfish/goldfish_nand.c:107:91: error: comparison of distinct pointer types lacks a cast [-Werror] goldfish/goldfish_nand.c: In function 'goldfish_nand_read_oob': goldfish/goldfish_nand.c:145:91: error: comparison of distinct pointer types lacks a cast [-Werror] This changes the code to the equivalent div_s64{,_rem} that works correctly for negative numbers (which we should never get here). The warning has shown up on ARM allmodconfig builds after the goldfish bus driver has become visible on ARM. Signed-off-by: Arnd Bergmann Fixes: bd2f348db503 ("goldfish: refactor goldfish platform configs") Acked-by: Alan Cox diff --git a/drivers/staging/goldfish/goldfish_nand.c b/drivers/staging/goldfish/goldfish_nand.c index f223b3a5a428..76d60eed1490 100644 --- a/drivers/staging/goldfish/goldfish_nand.c +++ b/drivers/staging/goldfish/goldfish_nand.c @@ -100,11 +100,11 @@ static int goldfish_nand_erase(struct mtd_info *mtd, struct erase_info *instr) { loff_t ofs = instr->addr; u32 len = instr->len; - u32 rem; + s32 rem; if (ofs + len > mtd->size) goto invalid_arg; - rem = do_div(ofs, mtd->writesize); + ofs = div_s64_rem(ofs, mtd->writesize, &rem); if (rem) goto invalid_arg; ofs *= (mtd->writesize + mtd->oobsize); @@ -133,7 +133,7 @@ invalid_arg: static int goldfish_nand_read_oob(struct mtd_info *mtd, loff_t ofs, struct mtd_oob_ops *ops) { - u32 rem; + s32 rem; if (ofs + ops->len > mtd->size) goto invalid_arg; @@ -142,7 +142,7 @@ static int goldfish_nand_read_oob(struct mtd_info *mtd, loff_t ofs, if (ops->ooblen + ops->ooboffs > mtd->oobsize) goto invalid_arg; - rem = do_div(ofs, mtd->writesize); + ofs = div_s64_rem(ofs, mtd->writesize, &rem); if (rem) goto invalid_arg; ofs *= (mtd->writesize + mtd->oobsize); @@ -165,7 +165,7 @@ invalid_arg: static int goldfish_nand_write_oob(struct mtd_info *mtd, loff_t ofs, struct mtd_oob_ops *ops) { - u32 rem; + s32 rem; if (ofs + ops->len > mtd->size) goto invalid_arg; @@ -174,7 +174,7 @@ static int goldfish_nand_write_oob(struct mtd_info *mtd, loff_t ofs, if (ops->ooblen + ops->ooboffs > mtd->oobsize) goto invalid_arg; - rem = do_div(ofs, mtd->writesize); + ofs = div_s64_rem(ofs, mtd->writesize, &rem); if (rem) goto invalid_arg; ofs *= (mtd->writesize + mtd->oobsize); @@ -197,12 +197,12 @@ invalid_arg: static int goldfish_nand_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { - u32 rem; + s32 rem; if (from + len > mtd->size) goto invalid_arg; - rem = do_div(from, mtd->writesize); + from = div_s64_rem(from, mtd->writesize, &rem); if (rem) goto invalid_arg; from *= (mtd->writesize + mtd->oobsize); @@ -219,12 +219,12 @@ invalid_arg: static int goldfish_nand_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { - u32 rem; + s32 rem; if (to + len > mtd->size) goto invalid_arg; - rem = do_div(to, mtd->writesize); + to = div_s64_rem(to, mtd->writesize, &rem); if (rem) goto invalid_arg; to *= (mtd->writesize + mtd->oobsize); @@ -240,12 +240,12 @@ invalid_arg: static int goldfish_nand_block_isbad(struct mtd_info *mtd, loff_t ofs) { - u32 rem; + s32 rem; if (ofs >= mtd->size) goto invalid_arg; - rem = do_div(ofs, mtd->erasesize); + ofs = div_s64_rem(ofs, mtd->writesize, &rem); if (rem) goto invalid_arg; ofs *= mtd->erasesize / mtd->writesize; @@ -261,12 +261,12 @@ invalid_arg: static int goldfish_nand_block_markbad(struct mtd_info *mtd, loff_t ofs) { - u32 rem; + s32 rem; if (ofs >= mtd->size) goto invalid_arg; - rem = do_div(ofs, mtd->erasesize); + ofs = div_s64_rem(ofs, mtd->writesize, &rem); if (rem) goto invalid_arg; ofs *= mtd->erasesize / mtd->writesize; @@ -321,7 +321,7 @@ static int goldfish_nand_init_device(struct platform_device *pdev, mtd->oobavail = mtd->oobsize; mtd->erasesize = readl(base + NAND_DEV_ERASE_SIZE) / (mtd->writesize + mtd->oobsize) * mtd->writesize; - do_div(mtd->size, mtd->writesize + mtd->oobsize); + mtd->size = div_s64(mtd->size, mtd->writesize + mtd->oobsize); mtd->size *= mtd->writesize; dev_dbg(&pdev->dev, "goldfish nand dev%d: size %llx, page %d, extra %d, erase %d\n",