From patchwork Tue Dec 14 11:27:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 75485 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 80AEF1007D5 for ; Tue, 14 Dec 2010 22:28:29 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756053Ab0LNL2B (ORCPT ); Tue, 14 Dec 2010 06:28:01 -0500 Received: from shutemov.name ([188.40.19.243]:40887 "EHLO shutemov.name" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751789Ab0LNL2A (ORCPT ); Tue, 14 Dec 2010 06:28:00 -0500 Received: by shutemov.name (Postfix, from userid 500) id 81EB7D417C; Tue, 14 Dec 2010 13:27:59 +0200 (EET) Date: Tue, 14 Dec 2010 13:27:59 +0200 From: "Kirill A. Shutemov" To: "Eric W. Biederman" Cc: "David S. Miller" , netdev@vger.kernel.org, Pablo Neira Ayuso , "Dmitry V. Levin" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] netlink: fix gcc -Wconversion compilation warning Message-ID: <20101214112759.GA13807@shutemov.name> References: <1292259913-9911-1-git-send-email-kirill@shutemov.name> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2010-08-04) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Mon, Dec 13, 2010 at 01:35:25PM -0800, Eric W. Biederman wrote: > "Kirill A. Shutsemov" writes: > > > From: Dmitry V. Levin > > > > $ cat << EOF | gcc -Wconversion -xc -S -o/dev/null - > > unsigned f(void) {return NLMSG_HDRLEN;} > > EOF > > : In function 'f': > > :3:26: warning: negative integer implicitly converted to unsigned type > > > This doesn't look like a bad fix, but I believe things will fail if > we give NLMSG_ALIGN an unsigned long like size_t. Say like sizeof. > > Admittedly it has to be a huge size but still if we are going > to go fixing things... > > And then there is the silliness that NLMSG_HDRLEN forces itself > to be an int, when it start out as a size_t. > > So I think NLMSG_ALIGN either needs to operation exclusively > on unsigned longs aka size_t, or it needs to be type preserving. > > Do you have time to look at this a bit more? Something like this? Untested. --- From 8b86073dc9697c0eff93c003d6331c1e4aeda60e Mon Sep 17 00:00:00 2001 From: Kirill A. Shutemov Date: Tue, 14 Dec 2010 12:50:39 +0200 Subject: [PATCH] netlink: fix gcc -Wconversion compilation warning $ cat << EOF | gcc -Wconversion -xc -S -o/dev/null - unsigned f(void) {return NLMSG_HDRLEN;} EOF : In function 'f': :3:26: warning: negative integer implicitly converted to unsigned type Define NLMSG_ALIGNTO as size_t, NLMSG_ALIGN always returns size_t and drop non-sense casting in NLMSG_HDRLEN. Now NLMSG_HDRLEN returns size_t. Signed-off-by: Dmitry V. Levin Signed-off-by: Kirill A. Shutemov --- include/linux/netlink.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/netlink.h b/include/linux/netlink.h index 1235669..db7d373 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h @@ -70,9 +70,9 @@ struct nlmsghdr { Check NLM_F_EXCL */ -#define NLMSG_ALIGNTO 4 -#define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) ) -#define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr))) +#define NLMSG_ALIGNTO ((size_t) 4) +#define NLMSG_ALIGN(len) ( ((size_t)(len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) ) +#define NLMSG_HDRLEN NLMSG_ALIGN(sizeof(struct nlmsghdr)) #define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(NLMSG_HDRLEN)) #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len)) #define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))