public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup: add explicit cast and comment for return type conversion
@ 2015-05-24 13:07 Nicholas Mc Guire
  2015-05-24 20:35 ` Tejun Heo
  0 siblings, 1 reply; 7+ messages in thread
From: Nicholas Mc Guire @ 2015-05-24 13:07 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Li Zefan, cgroups, linux-kernel, Nicholas Mc Guire

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;
 }
 
 static int cgroup_release_agent_show(struct seq_file *seq, void *v)
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-05-26  4:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox