linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4][Trivial] lib/kobject.c: Check parameter in kobject_get_path
@ 2012-04-21  9:25 yan
  2012-04-23 20:38 ` greg
  0 siblings, 1 reply; 2+ messages in thread
From: yan @ 2012-04-21  9:25 UTC (permalink / raw)
  To: greg; +Cc: kernel, message

kobject_get_path is exported, it passes its parameter kobj to
get_kobj_path_length and fill_kobj_path which are both static 
and called only once here. So check this parameter.


Signed-off-by: Yan Hong <clouds.yan@gmail.com>
---
 lib/kobject.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 38fcc60..56c8cb3 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -104,6 +104,9 @@ char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask)
 	char *path;
 	int len;
 
+	if (!kobj)
+		return NULL;
+
 	len = get_kobj_path_length(kobj);
 	if (len == 0)
 		return NULL;
-- 
1.7.5.1




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

* Re: [PATCH 1/4][Trivial] lib/kobject.c: Check parameter in kobject_get_path
  2012-04-21  9:25 [PATCH 1/4][Trivial] lib/kobject.c: Check parameter in kobject_get_path yan
@ 2012-04-23 20:38 ` greg
  0 siblings, 0 replies; 2+ messages in thread
From: greg @ 2012-04-23 20:38 UTC (permalink / raw)
  To: yan; +Cc: kernel, message

On Sat, Apr 21, 2012 at 05:25:42PM +0800, yan wrote:
> kobject_get_path is exported, it passes its parameter kobj to
> get_kobj_path_length and fill_kobj_path which are both static 
> and called only once here. So check this parameter.

Why?  If you call this function, you should pass in a valid pointer,
that's the proper way to call it.  No need to be "defensive" here at
all, if the caller messes up, then it crashes, as it should not be
making this type of call on a NULL pointer.

In looking at all of the in-kernel users of this function, they all do
this properly, so I see no need for this patch.

And these types of patches are not "trivial" at all, so please don't
mark them as such.

thanks,

greg k-h

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

end of thread, other threads:[~2012-04-23 20:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-21  9:25 [PATCH 1/4][Trivial] lib/kobject.c: Check parameter in kobject_get_path yan
2012-04-23 20:38 ` greg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).