Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S271374AbTHDCD6 (ORCPT ); Sun, 3 Aug 2003 22:03:58 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S271375AbTHDCD6 (ORCPT ); Sun, 3 Aug 2003 22:03:58 -0400 Received: from hera.cwi.nl ([192.16.191.8]:3544 "EHLO hera.cwi.nl") by vger.kernel.org with ESMTP id S271374AbTHDCD5 (ORCPT ); Sun, 3 Aug 2003 22:03:57 -0400 From: Andries.Brouwer@cwi.nl Date: Mon, 4 Aug 2003 04:03:53 +0200 (MEST) Message-Id: To: linux-kernel@vger.kernel.org Subject: do_div considered harmful Cc: torvalds@osdl.org Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 896 Lines: 23 Writing this ide capacity patch an hour ago or so I split off a helper sectors_to_MB() since Erik's recent patch uses this also. Now that I compare, he wrote nativeMb = do_div(nativeMb, 1000000); to divide nativeMb by 1000000. Similarly, I find in fs/cifs/inode.c inode->i_blocks = do_div(findData.NumOfBytes, inode->i_blksize); So, it seems natural to expect that do_div() gives the quotient. But it gives the remainder. (Strange, Erik showed correct output.) Since the semantics of this object are very unlike that of a C function, I wonder whether we should write DO_DIV instead, or DO_DIV_AND_REM to show that a remainder is returned. Andries - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/