LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [-mm3 patch]Warning fix: check the return value of kobject_add etc.
@ 2007-03-31  2:30 Cong WANG
  2007-04-01  5:31 ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Cong WANG @ 2007-03-31  2:30 UTC (permalink / raw)
  To: linux-kernel, Andrew Morton, viro

Since kobject_add, sysfs_create_link and sysfs_create_file are marked
as '__must_check', so we must always check their return values, or gcc
will give us warnings.

Signed-off-by: Cong WANG <xiyou.wangcong@gmail.com>

---
--- fs/partitions/check.c.orig	2007-03-30 21:35:45.000000000 +0800
+++ fs/partitions/check.c	2007-03-30 21:49:53.000000000 +0800
@@ -385,10 +385,16 @@ void add_partition(struct gendisk *disk,
 	p->kobj.parent = &disk->kobj;
 	p->kobj.ktype = &ktype_part;
 	kobject_init(&p->kobj);
-	kobject_add(&p->kobj);
+	if (kobject_add(&p->kobj)) {
+		kfree(p);
+		return;
+	}
 	if (!disk->part_uevent_suppress)
 		kobject_uevent(&p->kobj, KOBJ_ADD);
-	sysfs_create_link(&p->kobj, &block_subsys.kset.kobj, "subsystem");
+	if (sysfs_create_link(&p->kobj, &block_subsys.kset.kobj, "subsystem")) {
+		kfree(p);
+		return;
+	}
 	if (flags & ADDPART_FLAG_WHOLEDISK) {
 		static struct attribute addpartattr = {
 			.name = "whole_disk",
@@ -396,7 +402,10 @@ void add_partition(struct gendisk *disk,
 			.owner = THIS_MODULE,
 		};

-		sysfs_create_file(&p->kobj, &addpartattr);
+		if (sysfs_create_file(&p->kobj, &addpartattr)) {
+			kfree(p);
+			return;
+		}
 	}
 	partition_sysfs_add_subdir(p);
 	disk->part[part-1] = p;

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

* Re: [-mm3 patch]Warning fix: check the return value of kobject_add etc.
  2007-03-31  2:30 [-mm3 patch]Warning fix: check the return value of kobject_add etc Cong WANG
@ 2007-04-01  5:31 ` Andrew Morton
  2007-04-01  6:20   ` Cong WANG
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2007-04-01  5:31 UTC (permalink / raw)
  To: Cong WANG; +Cc: linux-kernel, viro

On Sat, 31 Mar 2007 10:30:31 +0800 "Cong WANG" <xiyou.wangcong@gmail.com> wrote:

> Since kobject_add, sysfs_create_link and sysfs_create_file are marked
> as '__must_check', so we must always check their return values, or gcc
> will give us warnings.
> 
> Signed-off-by: Cong WANG <xiyou.wangcong@gmail.com>
> 
> ---
> --- fs/partitions/check.c.orig	2007-03-30 21:35:45.000000000 +0800
> +++ fs/partitions/check.c	2007-03-30 21:49:53.000000000 +0800
> @@ -385,10 +385,16 @@ void add_partition(struct gendisk *disk,
>  	p->kobj.parent = &disk->kobj;
>  	p->kobj.ktype = &ktype_part;
>  	kobject_init(&p->kobj);
> -	kobject_add(&p->kobj);
> +	if (kobject_add(&p->kobj)) {
> +		kfree(p);
> +		return;
> +	}
>  	if (!disk->part_uevent_suppress)
>  		kobject_uevent(&p->kobj, KOBJ_ADD);
> -	sysfs_create_link(&p->kobj, &block_subsys.kset.kobj, "subsystem");
> +	if (sysfs_create_link(&p->kobj, &block_subsys.kset.kobj, "subsystem")) {
> +		kfree(p);
> +		return;
> +	}
>  	if (flags & ADDPART_FLAG_WHOLEDISK) {
>  		static struct attribute addpartattr = {
>  			.name = "whole_disk",
> @@ -396,7 +402,10 @@ void add_partition(struct gendisk *disk,
>  			.owner = THIS_MODULE,
>  		};
> 
> -		sysfs_create_file(&p->kobj, &addpartattr);
> +		if (sysfs_create_file(&p->kobj, &addpartattr)) {
> +			kfree(p);
> +			return;
> +		}
>  	}
>  	partition_sysfs_add_subdir(p);
>  	disk->part[part-1] = p;

Well yes, but the point here it to fix kernel bugs, not to just make the
warnings go away.

The bugs here are that the effects of the kobject_add() and the
sysfs_create_link() are not undone on the error path.

Also, please always prepare patches in `patch -p1' form, as per
http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt, thanks.


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

* Re: [-mm3 patch]Warning fix: check the return value of kobject_add etc.
  2007-04-01  5:31 ` Andrew Morton
@ 2007-04-01  6:20   ` Cong WANG
  2007-04-01  6:34     ` Andrew Morton
       [not found]     ` <376272831.09174@ustc.edu.cn>
  0 siblings, 2 replies; 7+ messages in thread
From: Cong WANG @ 2007-04-01  6:20 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel, viro

2007/4/1, Andrew Morton <akpm@linux-foundation.org>:
> On Sat, 31 Mar 2007 10:30:31 +0800 "Cong WANG" <xiyou.wangcong@gmail.com> wrote:
>
> > Since kobject_add, sysfs_create_link and sysfs_create_file are marked
> > as '__must_check', so we must always check their return values, or gcc
> > will give us warnings.
> >
> > Signed-off-by: Cong WANG <xiyou.wangcong@gmail.com>
> >
> > ---
> > --- fs/partitions/check.c.orig        2007-03-30 21:35:45.000000000 +0800
> > +++ fs/partitions/check.c     2007-03-30 21:49:53.000000000 +0800
> > @@ -385,10 +385,16 @@ void add_partition(struct gendisk *disk,
> >       p->kobj.parent = &disk->kobj;
> >       p->kobj.ktype = &ktype_part;
> >       kobject_init(&p->kobj);
> > -     kobject_add(&p->kobj);
> > +     if (kobject_add(&p->kobj)) {
> > +             kfree(p);
> > +             return;
> > +     }
> >       if (!disk->part_uevent_suppress)
> >               kobject_uevent(&p->kobj, KOBJ_ADD);
> > -     sysfs_create_link(&p->kobj, &block_subsys.kset.kobj, "subsystem");
> > +     if (sysfs_create_link(&p->kobj, &block_subsys.kset.kobj, "subsystem")) {
> > +             kfree(p);
> > +             return;
> > +     }
> >       if (flags & ADDPART_FLAG_WHOLEDISK) {
> >               static struct attribute addpartattr = {
> >                       .name = "whole_disk",
> > @@ -396,7 +402,10 @@ void add_partition(struct gendisk *disk,
> >                       .owner = THIS_MODULE,
> >               };
> >
> > -             sysfs_create_file(&p->kobj, &addpartattr);
> > +             if (sysfs_create_file(&p->kobj, &addpartattr)) {
> > +                     kfree(p);
> > +                     return;
> > +             }
> >       }
> >       partition_sysfs_add_subdir(p);
> >       disk->part[part-1] = p;
>
> Well yes, but the point here it to fix kernel bugs, not to just make the
> warnings go away.
>
> The bugs here are that the effects of the kobject_add() and the
> sysfs_create_link() are not undone on the error path.

Thanks for your point.

>
> Also, please always prepare patches in `patch -p1' form, as per
> http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt, thanks.
>
>

Sorry. I am confused with this. Does that mean I should make patches
_upon_ the root kernel source directory or first make a copy of the
original source code and then diff against the two dirs? But I was
told that "patches should be based _in_ the root kernel source
directory" and when only one file was modified just to diff it with
the original single file. (See Documentation/SubmittingPatches.)

Can you help out? And should I remake this patch? Thanks again!

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

* Re: [-mm3 patch]Warning fix: check the return value of kobject_add etc.
  2007-04-01  6:20   ` Cong WANG
@ 2007-04-01  6:34     ` Andrew Morton
  2007-04-01  6:46       ` Cong WANG
       [not found]     ` <376272831.09174@ustc.edu.cn>
  1 sibling, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2007-04-01  6:34 UTC (permalink / raw)
  To: Cong WANG; +Cc: linux-kernel, viro

On Sun, 1 Apr 2007 14:20:46 +0800 "Cong WANG" <xiyou.wangcong@gmail.com> wrote:

> 
> >
> > Also, please always prepare patches in `patch -p1' form, as per
> > http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt, thanks.
> >
> >
> 
> Sorry. I am confused with this. Does that mean I should make patches
> _upon_ the root kernel source directory or first make a copy of the
> original source code and then diff against the two dirs? But I was
> told that "patches should be based _in_ the root kernel source
> directory" and when only one file was modified just to diff it with
> the original single file. (See Documentation/SubmittingPatches.)

The headers should look like:

--- a/arch/cris/kernel/crisksyms.c
+++ a/arch/cris/kernel/crisksyms.c

I don't know how people do that.  One obvious way is to do

cd /usr/src
diff -u linux-orig/arch/cris/kernel/crisksyms.c linux-new/arch/cris/kernel/crisksyms.c

other people probably alter the diff headers.

> And should I remake this patch?

Sure, but please change it to perform correct error handling first.  And
test that error handling, if you can.  That will involve adding artificial
errors.

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

* Re: [-mm3 patch]Warning fix: check the return value of kobject_add etc.
  2007-04-01  6:34     ` Andrew Morton
@ 2007-04-01  6:46       ` Cong WANG
  0 siblings, 0 replies; 7+ messages in thread
From: Cong WANG @ 2007-04-01  6:46 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel; +Cc: viro

2007/4/1, Andrew Morton <akpm@linux-foundation.org>:
> On Sun, 1 Apr 2007 14:20:46 +0800 "Cong WANG" <xiyou.wangcong@gmail.com> wrote:
>
> >
> > >
> > > Also, please always prepare patches in `patch -p1' form, as per
> > > http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt, thanks.
> > >
> > >
> >
> > Sorry. I am confused with this. Does that mean I should make patches
> > _upon_ the root kernel source directory or first make a copy of the
> > original source code and then diff against the two dirs? But I was
> > told that "patches should be based _in_ the root kernel source
> > directory" and when only one file was modified just to diff it with
> > the original single file. (See Documentation/SubmittingPatches.)
>
> The headers should look like:
>
> --- a/arch/cris/kernel/crisksyms.c
> +++ a/arch/cris/kernel/crisksyms.c
>
> I don't know how people do that.  One obvious way is to do
>
> cd /usr/src
> diff -u linux-orig/arch/cris/kernel/crisksyms.c linux-new/arch/cris/kernel/crisksyms.c
>
> other people probably alter the diff headers.

Oh, thanks. I know.

>
> > And should I remake this patch?
>
> Sure, but please change it to perform correct error handling first.  And
> test that error handling, if you can.  That will involve adding artificial
> errors.
>

I will remake it soon and send it again.

In fact, I have just tested it roughly. And I don't how to produce
artificial errors. Sorry, I hope someone can help me to test it
carefully.

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

* Re: [-mm3 patch]Warning fix: check the return value of kobject_add etc.
       [not found]     ` <376272831.09174@ustc.edu.cn>
@ 2007-04-11  6:23       ` Fengguang Wu
  2007-04-11  6:48         ` WANG Cong
  0 siblings, 1 reply; 7+ messages in thread
From: Fengguang Wu @ 2007-04-11  6:23 UTC (permalink / raw)
  To: Cong WANG; +Cc: Andrew Morton, linux-kernel, viro

On Sun, Apr 01, 2007 at 02:20:46PM +0800, Cong WANG wrote:
> 2007/4/1, Andrew Morton <akpm@linux-foundation.org>:
> >
> >Also, please always prepare patches in `patch -p1' form, as per
> >http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt, thanks.
> >
> >
> 
> Sorry. I am confused with this. Does that mean I should make patches
> _upon_ the root kernel source directory or first make a copy of the
> original source code and then diff against the two dirs? But I was
> told that "patches should be based _in_ the root kernel source
> directory" and when only one file was modified just to diff it with
> the original single file. (See Documentation/SubmittingPatches.)
> 
> Can you help out? And should I remake this patch? Thanks again!

quilt(http://savannah.nongnu.org/projects/quilt) is your friend.

cd /usr/src/linux
quilt new my-fix.patch
quilt edit mm/readahead.c
quilt refresh --diffstat
quilt diff
...

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

* Re: [-mm3 patch]Warning fix: check the return value of kobject_add etc.
  2007-04-11  6:23       ` Fengguang Wu
@ 2007-04-11  6:48         ` WANG Cong
  0 siblings, 0 replies; 7+ messages in thread
From: WANG Cong @ 2007-04-11  6:48 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel, viro

On Wed, Apr 11, 2007 at 02:23:49PM +0800, Fengguang Wu wrote:
>On Sun, Apr 01, 2007 at 02:20:46PM +0800, Cong WANG wrote:
>> 2007/4/1, Andrew Morton <akpm@linux-foundation.org>:
>> >
>> >Also, please always prepare patches in `patch -p1' form, as per
>> >http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt, thanks.
>> >
>> >
>> 
>> Sorry. I am confused with this. Does that mean I should make patches
>> _upon_ the root kernel source directory or first make a copy of the
>> original source code and then diff against the two dirs? But I was
>> told that "patches should be based _in_ the root kernel source
>> directory" and when only one file was modified just to diff it with
>> the original single file. (See Documentation/SubmittingPatches.)
>> 
>> Can you help out? And should I remake this patch? Thanks again!
>
>quilt(http://savannah.nongnu.org/projects/quilt) is your friend.
>
>cd /usr/src/linux
>quilt new my-fix.patch
>quilt edit mm/readahead.c
>quilt refresh --diffstat
>quilt diff
>...

Thanks. I will try it. ;-)


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

end of thread, other threads:[~2007-04-11  6:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-31  2:30 [-mm3 patch]Warning fix: check the return value of kobject_add etc Cong WANG
2007-04-01  5:31 ` Andrew Morton
2007-04-01  6:20   ` Cong WANG
2007-04-01  6:34     ` Andrew Morton
2007-04-01  6:46       ` Cong WANG
     [not found]     ` <376272831.09174@ustc.edu.cn>
2007-04-11  6:23       ` Fengguang Wu
2007-04-11  6:48         ` WANG Cong

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).