public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicholas Mc Guire <der.herr@hofr.at>
To: Tejun Heo <tj@kernel.org>
Cc: Nicholas Mc Guire <hofrat@osadl.org>,
	Li Zefan <lizefan@huawei.com>,
	cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cgroup: add explicit cast and comment for return type conversion
Date: Mon, 25 May 2015 07:57:42 +0200	[thread overview]
Message-ID: <20150525055742.GE1397@opentech.at> (raw)
In-Reply-To: <20150524203528.GB7099@htj.duckdns.org>

On Sun, 24 May 2015, Tejun Heo wrote:

> 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 <hofrat@osadl.org>
> > ---
> > 
> > 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?
>
nop not downward but signed/unsigned  if it were down it would not be
a problem but signed/unsigned can be - for those cases where it can't
be fixed up by changing the declarations or return variable types 
explicit cast might make sense - as noted in the patch Im not sure either
if this form of cleanups is helpful. 

In the kernel core there are about 400 signed/unsigned implicit 
conversions (about 3k in the entire kernel) which is what Im trying to 
remove or if that is not possible in a resonable way mark as false positive.

thx!
hofrat

  reply	other threads:[~2015-05-25  5:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-24 13:07 [PATCH] cgroup: add explicit cast and comment for return type conversion Nicholas Mc Guire
2015-05-24 20:35 ` Tejun Heo
2015-05-25  5:57   ` Nicholas Mc Guire [this message]
2015-05-25 11:40     ` Tejun Heo
2015-05-25 11:50       ` Nicholas Mc Guire
2015-05-26  0:05         ` Tejun Heo
2015-05-26  4:52           ` Nicholas Mc Guire

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150525055742.GE1397@opentech.at \
    --to=der.herr@hofr.at \
    --cc=cgroups@vger.kernel.org \
    --cc=hofrat@osadl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox