Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751695AbbEXUff (ORCPT ); Sun, 24 May 2015 16:35:35 -0400 Received: from mail-qk0-f173.google.com ([209.85.220.173]:34691 "EHLO mail-qk0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751275AbbEXUfc (ORCPT ); Sun, 24 May 2015 16:35:32 -0400 Date: Sun, 24 May 2015 16:35:28 -0400 From: Tejun Heo To: Nicholas Mc Guire Cc: Li Zefan , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] cgroup: add explicit cast and comment for return type conversion Message-ID: <20150524203528.GB7099@htj.duckdns.org> References: <1432472872-3578-1-git-send-email-hofrat@osadl.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1432472872-3578-1-git-send-email-hofrat@osadl.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1964 Lines: 54 Hello, On Sun, May 24, 2015 at 03:07:52PM +0200, Nicholas Mc Guire wrote: > Type-checking coccinelle spatches are being used to locate type mismatches > between function signatures and return values in this case this produced: > ./kernel/cgroup.c:2525 WARNING: return of wrong type > ssize_t != size_t, > > Returning unsigned types converted to a signed type can be problematic > but in this case the size_t is <= PATH_MAX which is less than ulong/2 so > the conversion is safe - to make static code checking happy this is > resolved by an explicit cast and appropriate comment. > > Patch was compile tested with x86_64_defconfig (implies CONFIG_CGROUPS=y) > > Patch is against 4.1-rc4 (localversion-next is -next-20150522) > > Signed-off-by: Nicholas Mc Guire > --- > > Not sure if "cleanups" like this are acceptable - in this case I did not > find any better way to make static code checkers happy though. > > kernel/cgroup.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/kernel/cgroup.c b/kernel/cgroup.c > index b91177f..04de621 100644 > --- a/kernel/cgroup.c > +++ b/kernel/cgroup.c > @@ -2523,7 +2523,11 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of, > sizeof(cgrp->root->release_agent_path)); > spin_unlock(&release_agent_path_lock); > cgroup_kn_unlock(of->kn); > - return nbytes; > + > + /* the path of the release notifier is <= PATH_MAX > + * so "downsizing" to signed long is safe here > + */ > + return (ssize_t)nbytes; idk, does this actually help anything? This isn't different from any other implicit type casts. Are we gonna convert all downward implicit casts to be explicit? Thanks. -- tejun -- 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/