Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3690657imm; Mon, 18 Jun 2018 02:22:00 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIBTexjJ9R/R2LNTjBGshLC3gUCHowgT0As3nDRnRvyaeJS2orQGBftllNjgoE3w16cw4lW X-Received: by 2002:a63:a84f:: with SMTP id i15-v6mr10591159pgp.422.1529313720807; Mon, 18 Jun 2018 02:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529313720; cv=none; d=google.com; s=arc-20160816; b=Riwc8CpKEoEj+9g4ITJkgHsHOCuP+JWebG4jpvgq/OyiuepRYTFPy8gUobzSP34tBe yUAlsTIoNqhMpPecxVGsUxgVgV99Be4sbJr3IfuwCONTAiz/0To34Ny6DDQchLifIhKc xje+Pm1PK03N88BnSX65Gdc6KgB7sMR37vRP3KDT5IfBOiX+wm5zdpg3rGV4+2XMHQIN vVHRQ//pnY7T8mHgyx4dtjdbGegxn+GaAzpyMOkqhm/nFqGIFZEnXPfRWO3UCb8C9bEV kCvsM1vInlnhMsrLBEIj1jKWm0MJE55NOLlAMmRXWottjhywaBTHR0pUk0rpMUOLCDDG fgPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=YZ386TATyeZfgx59tjmC68HG7w8BDGwuERmMjvwQrOs=; b=cga9bk1ITR6GOpGOxOkmXsL/QLif4tL8zOhBDLsjNEoAIpC0jH8C+EkYUhzEzsWr6l /X2GA1BEthdLNCyqiHDv0iRA9kuyjdzFzsSMOruBUBJ1/GCUZoZ35Eh7jlyKL5fnPaND 91hRdFOOQ79+py6AmBS7fd/IfLyE3Zp0t1glfTJgmzHqs8Xh1lt1JZAbDYu/ISE/6d7o x/LUP96OYlTus21VEJjpvwFcdJXbkVG9dc8jPws1mRwwIfJm9ptS18/nLop3WUaT28Gu duR30Naz/v3J70ae+wiXKnOl/5/TF5/N6d8016xM5fiMZhBVhXNwJRwG1AM5tjfjv+Wi 0c/w== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y20-v6si14677783plp.267.2018.06.18.02.21.43; Mon, 18 Jun 2018 02:22:00 -0700 (PDT) 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 S966523AbeFRI1w (ORCPT + 99 others); Mon, 18 Jun 2018 04:27:52 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58340 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966478AbeFRI1t (ORCPT ); Mon, 18 Jun 2018 04:27:49 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6C297CA8; Mon, 18 Jun 2018 08:27:48 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Boris Brezillon , Sasha Levin Subject: [PATCH 4.16 265/279] mtd: rawnand: Fix return type of __DIVIDE() when called with 32-bit Date: Mon, 18 Jun 2018 10:14:10 +0200 Message-Id: <20180618080619.666252265@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618080608.851973560@linuxfoundation.org> References: <20180618080608.851973560@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Geert Uytterhoeven [ Upstream commit 9f825e74d761c13b0cfaa5f65344d64ff970e252 ] The __DIVIDE() macro checks whether it is called with a 32-bit or 64-bit dividend, to select the appropriate divide-and-round-up routine. As the check uses the ternary operator, the result will always be promoted to a type that can hold both results, i.e. unsigned long long. When using this result in a division on a 32-bit system, this may lead to link errors like: ERROR: "__udivdi3" [drivers/mtd/nand/raw/nand.ko] undefined! Fix this by casting the result of the division to the type of the dividend. Fixes: 8878b126df769831 ("mtd: nand: add ->exec_op() implementation") Signed-off-by: Geert Uytterhoeven Signed-off-by: Boris Brezillon Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/linux/mtd/rawnand.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -824,12 +824,18 @@ struct nand_op_instr { * tBERS (during an erase) which all of them are u64 values that cannot be * divided by usual kernel macros and must be handled with the special * DIV_ROUND_UP_ULL() macro. + * + * Cast to type of dividend is needed here to guarantee that the result won't + * be an unsigned long long when the dividend is an unsigned long (or smaller), + * which is what the compiler does when it sees ternary operator with 2 + * different return types (picks the largest type to make sure there's no + * loss). */ -#define __DIVIDE(dividend, divisor) ({ \ - sizeof(dividend) == sizeof(u32) ? \ - DIV_ROUND_UP(dividend, divisor) : \ - DIV_ROUND_UP_ULL(dividend, divisor); \ - }) +#define __DIVIDE(dividend, divisor) ({ \ + (__typeof__(dividend))(sizeof(dividend) <= sizeof(unsigned long) ? \ + DIV_ROUND_UP(dividend, divisor) : \ + DIV_ROUND_UP_ULL(dividend, divisor)); \ + }) #define PSEC_TO_NSEC(x) __DIVIDE(x, 1000) #define PSEC_TO_MSEC(x) __DIVIDE(x, 1000000000)