All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
@ 2009-11-15  1:52 Joe Perches
  2009-11-15  6:59 ` Américo Wang
  0 siblings, 1 reply; 18+ messages in thread
From: Joe Perches @ 2009-11-15  1:52 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar, Andrew Morton

Seems to be a typo.

Signed-off-by: Joe Perches <joe@perches.com>

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 0d949c5..d0bf4eb 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1605,7 +1605,7 @@ static struct ctl_table debug_table[] = {
 		.data		= &show_unhandled_signals,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec
+		.proc_handler	= &proc_dointvec,
 	},
 #endif
 	{ .ctl_name = 0 }



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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15  1:52 [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec, Joe Perches
@ 2009-11-15  6:59 ` Américo Wang
  2009-11-15  8:11   ` Ingo Molnar
  0 siblings, 1 reply; 18+ messages in thread
From: Américo Wang @ 2009-11-15  6:59 UTC (permalink / raw)
  To: Joe Perches; +Cc: LKML, Ingo Molnar, Andrew Morton

On Sat, Nov 14, 2009 at 05:52:05PM -0800, Joe Perches wrote:
>Seems to be a typo.
>

Well, in this case, proc_dointvec == &proc_dointvec,
both of them are the same function pointer.

But yes, &proc_dointvec looks more readable.

>Signed-off-by: Joe Perches <joe@perches.com>

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

>
>diff --git a/kernel/sysctl.c b/kernel/sysctl.c
>index 0d949c5..d0bf4eb 100644
>--- a/kernel/sysctl.c
>+++ b/kernel/sysctl.c
>@@ -1605,7 +1605,7 @@ static struct ctl_table debug_table[] = {
> 		.data		= &show_unhandled_signals,
> 		.maxlen		= sizeof(int),
> 		.mode		= 0644,
>-		.proc_handler	= proc_dointvec
>+		.proc_handler	= &proc_dointvec,
> 	},
> #endif
> 	{ .ctl_name = 0 }
>
>
>--
>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/

-- 
Live like a child, think like the god.
 

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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15  6:59 ` Américo Wang
@ 2009-11-15  8:11   ` Ingo Molnar
  2009-11-15  8:28     ` Joe Perches
  0 siblings, 1 reply; 18+ messages in thread
From: Ingo Molnar @ 2009-11-15  8:11 UTC (permalink / raw)
  To: Am??rico Wang, Eric W. Biederman; +Cc: Joe Perches, LKML, Andrew Morton


* Am??rico Wang <xiyou.wangcong@gmail.com> wrote:

> On Sat, Nov 14, 2009 at 05:52:05PM -0800, Joe Perches wrote:
> >Seems to be a typo.
> >
> 
> Well, in this case, proc_dointvec == &proc_dointvec,
> both of them are the same function pointer.
> 
> But yes, &proc_dointvec looks more readable.
> 
> >Signed-off-by: Joe Perches <joe@perches.com>
> 
> Acked-by: WANG Cong <xiyou.wangcong@gmail.com>

(Cc:-ed Eric who is running the sysctl tree these days)

Almost everywhere in the kernel we use the shorter version, so all of 
sysctl.c should eventually change to that variant.

	Ingo

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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15  8:11   ` Ingo Molnar
@ 2009-11-15  8:28     ` Joe Perches
  2009-11-15  8:39       ` Ingo Molnar
  0 siblings, 1 reply; 18+ messages in thread
From: Joe Perches @ 2009-11-15  8:28 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Am??rico Wang, Eric W. Biederman, LKML, Andrew Morton

On Sun, 2009-11-15 at 09:11 +0100, Ingo Molnar wrote:
> * Am??rico Wang <xiyou.wangcong@gmail.com> wrote:
> > On Sat, Nov 14, 2009 at 05:52:05PM -0800, Joe Perches wrote:
> > >Seems to be a typo.
> > Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
> (Cc:-ed Eric who is running the sysctl tree these days)
> Almost everywhere in the kernel we use the shorter version, so all of 
> sysctl.c should eventually change to that variant.

It's closer to 50/50, but it's 1 vs 133 in that file.

$ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*&\s*\w+' * | wc -l
339

$ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*[^&]\s*\w+' * | wc -l
432



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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15  8:28     ` Joe Perches
@ 2009-11-15  8:39       ` Ingo Molnar
  2009-11-15 10:04         ` Eric W. Biederman
  0 siblings, 1 reply; 18+ messages in thread
From: Ingo Molnar @ 2009-11-15  8:39 UTC (permalink / raw)
  To: Joe Perches; +Cc: Am??rico Wang, Eric W. Biederman, LKML, Andrew Morton


* Joe Perches <joe@perches.com> wrote:

> On Sun, 2009-11-15 at 09:11 +0100, Ingo Molnar wrote:
> > * Am??rico Wang <xiyou.wangcong@gmail.com> wrote:
> > > On Sat, Nov 14, 2009 at 05:52:05PM -0800, Joe Perches wrote:
> > > >Seems to be a typo.
> > > Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
> > (Cc:-ed Eric who is running the sysctl tree these days)
> > Almost everywhere in the kernel we use the shorter version, so all of 
> > sysctl.c should eventually change to that variant.
> 
> It's closer to 50/50, but it's 1 vs 133 in that file.
> 
> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*&\s*\w+' * | wc -l
> 339
> 
> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*[^&]\s*\w+' * | wc -l
> 432

I did not mean this specific initialization method of proc_handler, i 
meant pointers to functions in general.

	Ingo

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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15  8:39       ` Ingo Molnar
@ 2009-11-15 10:04         ` Eric W. Biederman
  2009-11-15 10:33           ` Ingo Molnar
  0 siblings, 1 reply; 18+ messages in thread
From: Eric W. Biederman @ 2009-11-15 10:04 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Joe Perches, Am??rico Wang, LKML, Andrew Morton

Ingo Molnar <mingo@elte.hu> writes:

> * Joe Perches <joe@perches.com> wrote:
>
>> On Sun, 2009-11-15 at 09:11 +0100, Ingo Molnar wrote:
>> > * Am??rico Wang <xiyou.wangcong@gmail.com> wrote:
>> > > On Sat, Nov 14, 2009 at 05:52:05PM -0800, Joe Perches wrote:
>> > > >Seems to be a typo.
>> > > Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
>> > (Cc:-ed Eric who is running the sysctl tree these days)
>> > Almost everywhere in the kernel we use the shorter version, so all of 
>> > sysctl.c should eventually change to that variant.
>> 
>> It's closer to 50/50, but it's 1 vs 133 in that file.
>> 
>> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*&\s*\w+' * | wc -l
>> 339
>> 
>> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*[^&]\s*\w+' * | wc -l
>> 432
>
> I did not mean this specific initialization method of proc_handler, i 
> meant pointers to functions in general.


There was an argument put forward by Alexy (I think) a while ago.  That
argued for the form without the address of operator.

The reason being that without it you can do:
#define proc_dointvec NULL

in a header when sysctl support it compiled out.  Using address of
you wind up with stub functions in sysctl.c to handle the case when
sysctl is compiled out.

It isn't a strong case but since not using & is also shorter and
as Ingo pointed out more common I think no & wins.

Eric

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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 10:04         ` Eric W. Biederman
@ 2009-11-15 10:33           ` Ingo Molnar
  2009-11-15 12:29             ` Eric W. Biederman
  2009-11-15 17:31             ` Joe Perches
  0 siblings, 2 replies; 18+ messages in thread
From: Ingo Molnar @ 2009-11-15 10:33 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: Joe Perches, Am??rico Wang, LKML, Andrew Morton


* Eric W. Biederman <ebiederm@xmission.com> wrote:

> Ingo Molnar <mingo@elte.hu> writes:
> 
> > * Joe Perches <joe@perches.com> wrote:
> >
> >> On Sun, 2009-11-15 at 09:11 +0100, Ingo Molnar wrote:
> >> > * Am??rico Wang <xiyou.wangcong@gmail.com> wrote:
> >> > > On Sat, Nov 14, 2009 at 05:52:05PM -0800, Joe Perches wrote:
> >> > > >Seems to be a typo.
> >> > > Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
> >> > (Cc:-ed Eric who is running the sysctl tree these days)
> >> > Almost everywhere in the kernel we use the shorter version, so all of 
> >> > sysctl.c should eventually change to that variant.
> >> 
> >> It's closer to 50/50, but it's 1 vs 133 in that file.
> >> 
> >> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*&\s*\w+' * | wc -l
> >> 339
> >> 
> >> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*[^&]\s*\w+' * | wc -l
> >> 432
> >
> > I did not mean this specific initialization method of proc_handler, i 
> > meant pointers to functions in general.
> 
> 
> There was an argument put forward by Alexy (I think) a while ago.  
> That argued for the form without the address of operator.
> 
> The reason being that without it you can do:
> #define proc_dointvec NULL
> 
> in a header when sysctl support it compiled out.  Using address of
> you wind up with stub functions in sysctl.c to handle the case when
> sysctl is compiled out.
> 
> It isn't a strong case but since not using & is also shorter and as 
> Ingo pointed out more common I think no & wins.

I can think of another reason as well: the & operator can be dangerous 
if code is changed from functions to function pointers.

The short form:

  val = do_my_func;

will work just fine if 'my_func' is changed to a function pointer, as it 
will evaluate to the value of the function pointer - i.e. the address of 
the function.

The longer form:

  val = &do_my_func;

might break in a subtle way, because it will now become the address of 
the function pointer - not the function address.

Combined the shortness, the NULL init, the function pointer invariance, 
plus existing in-kernel practice all suggest that the short form should 
be used.

( i didnt want to turn this small issue into a long argument - it's just
  that the code was going in the wrong direction. )

	Ingo

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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 10:33           ` Ingo Molnar
@ 2009-11-15 12:29             ` Eric W. Biederman
  2009-11-15 13:57               ` Ingo Molnar
  2009-11-15 17:31             ` Joe Perches
  1 sibling, 1 reply; 18+ messages in thread
From: Eric W. Biederman @ 2009-11-15 12:29 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Joe Perches, Am??rico Wang, LKML, Andrew Morton

Ingo Molnar <mingo@elte.hu> writes:

> * Eric W. Biederman <ebiederm@xmission.com> wrote:
>
>> Ingo Molnar <mingo@elte.hu> writes:
>> 
>> > * Joe Perches <joe@perches.com> wrote:
>> >
>> >> On Sun, 2009-11-15 at 09:11 +0100, Ingo Molnar wrote:
>> >> > * Am??rico Wang <xiyou.wangcong@gmail.com> wrote:
>> >> > > On Sat, Nov 14, 2009 at 05:52:05PM -0800, Joe Perches wrote:
>> >> > > >Seems to be a typo.
>> >> > > Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
>> >> > (Cc:-ed Eric who is running the sysctl tree these days)
>> >> > Almost everywhere in the kernel we use the shorter version, so all of 
>> >> > sysctl.c should eventually change to that variant.
>> >> 
>> >> It's closer to 50/50, but it's 1 vs 133 in that file.
>> >> 
>> >> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*&\s*\w+' * | wc -l
>> >> 339
>> >> 
>> >> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*[^&]\s*\w+' * | wc -l
>> >> 432
>> >
>> > I did not mean this specific initialization method of proc_handler, i 
>> > meant pointers to functions in general.
>> 
>> 
>> There was an argument put forward by Alexy (I think) a while ago.  
>> That argued for the form without the address of operator.
>> 
>> The reason being that without it you can do:
>> #define proc_dointvec NULL
>> 
>> in a header when sysctl support it compiled out.  Using address of
>> you wind up with stub functions in sysctl.c to handle the case when
>> sysctl is compiled out.
>> 
>> It isn't a strong case but since not using & is also shorter and as 
>> Ingo pointed out more common I think no & wins.
>
> I can think of another reason as well: the & operator can be dangerous 
> if code is changed from functions to function pointers.
>
> The short form:
>
>   val = do_my_func;
>
> will work just fine if 'my_func' is changed to a function pointer, as it 
> will evaluate to the value of the function pointer - i.e. the address of 
> the function.
>
> The longer form:
>
>   val = &do_my_func;
>
> might break in a subtle way, because it will now become the address of 
> the function pointer - not the function address.
>
> Combined the shortness, the NULL init, the function pointer invariance, 
> plus existing in-kernel practice all suggest that the short form should 
> be used.
>
> ( i didnt want to turn this small issue into a long argument - it's just
>   that the code was going in the wrong direction. )

No problem here.  I'm still working through how to keep my tree from
conflicting with the net tree, big sweeping tend to have that problem,
but if someone wants to generate the & removal patches (against my
tree) and send them to me I will be happy to host them.  I am already
touching practically every sysctl table in the tree.

Eric



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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 12:29             ` Eric W. Biederman
@ 2009-11-15 13:57               ` Ingo Molnar
  2009-11-15 14:14                 ` Eric W. Biederman
  0 siblings, 1 reply; 18+ messages in thread
From: Ingo Molnar @ 2009-11-15 13:57 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: Joe Perches, Am??rico Wang, LKML, Andrew Morton


* Eric W. Biederman <ebiederm@xmission.com> wrote:

> Ingo Molnar <mingo@elte.hu> writes:
> 
> > * Eric W. Biederman <ebiederm@xmission.com> wrote:
> >
> >> Ingo Molnar <mingo@elte.hu> writes:
> >> 
> >> > * Joe Perches <joe@perches.com> wrote:
> >> >
> >> >> On Sun, 2009-11-15 at 09:11 +0100, Ingo Molnar wrote:
> >> >> > * Am??rico Wang <xiyou.wangcong@gmail.com> wrote:
> >> >> > > On Sat, Nov 14, 2009 at 05:52:05PM -0800, Joe Perches wrote:
> >> >> > > >Seems to be a typo.
> >> >> > > Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
> >> >> > (Cc:-ed Eric who is running the sysctl tree these days)
> >> >> > Almost everywhere in the kernel we use the shorter version, so all of 
> >> >> > sysctl.c should eventually change to that variant.
> >> >> 
> >> >> It's closer to 50/50, but it's 1 vs 133 in that file.
> >> >> 
> >> >> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*&\s*\w+' * | wc -l
> >> >> 339
> >> >> 
> >> >> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*[^&]\s*\w+' * | wc -l
> >> >> 432
> >> >
> >> > I did not mean this specific initialization method of proc_handler, i 
> >> > meant pointers to functions in general.
> >> 
> >> 
> >> There was an argument put forward by Alexy (I think) a while ago.  
> >> That argued for the form without the address of operator.
> >> 
> >> The reason being that without it you can do:
> >> #define proc_dointvec NULL
> >> 
> >> in a header when sysctl support it compiled out.  Using address of
> >> you wind up with stub functions in sysctl.c to handle the case when
> >> sysctl is compiled out.
> >> 
> >> It isn't a strong case but since not using & is also shorter and as 
> >> Ingo pointed out more common I think no & wins.
> >
> > I can think of another reason as well: the & operator can be dangerous 
> > if code is changed from functions to function pointers.
> >
> > The short form:
> >
> >   val = do_my_func;
> >
> > will work just fine if 'my_func' is changed to a function pointer, as it 
> > will evaluate to the value of the function pointer - i.e. the address of 
> > the function.
> >
> > The longer form:
> >
> >   val = &do_my_func;
> >
> > might break in a subtle way, because it will now become the address of 
> > the function pointer - not the function address.
> >
> > Combined the shortness, the NULL init, the function pointer invariance, 
> > plus existing in-kernel practice all suggest that the short form should 
> > be used.
> >
> > ( i didnt want to turn this small issue into a long argument - it's just
> >   that the code was going in the wrong direction. )
> 
> No problem here.  I'm still working through how to keep my tree from 
> conflicting with the net tree, big sweeping tend to have that problem, 
> but if someone wants to generate the & removal patches (against my 
> tree) and send them to me I will be happy to host them.  I am already 
> touching practically every sysctl table in the tree.

The preferred flow is for you to just work against Linus's latest tree - 
and everyone will deal with the (mostly trivial) conflicts when they 
happen. Linus prefers to resolve conflicts himself when he pulls, 
because people mixing their trees (such as you basing on net-next for 
example) leads to various dependency problems.

	Ingo

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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 13:57               ` Ingo Molnar
@ 2009-11-15 14:14                 ` Eric W. Biederman
  0 siblings, 0 replies; 18+ messages in thread
From: Eric W. Biederman @ 2009-11-15 14:14 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Joe Perches, Am??rico Wang, LKML, Andrew Morton

Ingo Molnar <mingo@elte.hu> writes:

> The preferred flow is for you to just work against Linus's latest tree - 
> and everyone will deal with the (mostly trivial) conflicts when they 
> happen. Linus prefers to resolve conflicts himself when he pulls, 
> because people mixing their trees (such as you basing on net-next for 
> example) leads to various dependency problems.

Sounds right.

I'm still getting up the courage to conflict.  I was wondering if I
could cherry pick a patch or two to avoid those.

Right now in the net tree there is one new sysctl and one bug fix to a
sysctl strategy routine I intend to delete.

The core or my changes are in.  This is just purging dead code.

It looks like those two changes may actually be single patches so I
could cherry pick them and in theory have no conflicts.

At the very least I'm going to wait for one more build of net-next with
everything but my network stack changes before I add those.

So far the conflicts are pretty minimal so I guess it doesn't matter
much.

Eric

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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 10:33           ` Ingo Molnar
  2009-11-15 12:29             ` Eric W. Biederman
@ 2009-11-15 17:31             ` Joe Perches
  2009-11-15 18:20               ` Julia Lawall
  1 sibling, 1 reply; 18+ messages in thread
From: Joe Perches @ 2009-11-15 17:31 UTC (permalink / raw)
  To: Ingo Molnar, julia Lawall
  Cc: Eric W. Biederman, Am??rico Wang, LKML, Andrew Morton

On Sun, 2009-11-15 at 11:33 +0100, Ingo Molnar wrote:
> * Eric W. Biederman <ebiederm@xmission.com> wrote:
> > Ingo Molnar <mingo@elte.hu> writes:
> > > * Joe Perches <joe@perches.com> wrote:
> > >> On Sun, 2009-11-15 at 09:11 +0100, Ingo Molnar wrote:
> > >> > * Am??rico Wang <xiyou.wangcong@gmail.com> wrote:
> > >> > > On Sat, Nov 14, 2009 at 05:52:05PM -0800, Joe Perches wrote:
> > >> > > >Seems to be a typo.
> > >> > > Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
> > >> > (Cc:-ed Eric who is running the sysctl tree these days)
> > >> > Almost everywhere in the kernel we use the shorter version, so all of 
> > >> > sysctl.c should eventually change to that variant.
> > >> It's closer to 50/50, but it's 1 vs 133 in that file.
> > >> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*&\s*\w+' * | wc -l
> > >> 339
> > >> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*[^&]\s*\w+' * | wc -l
> > >> 432
> > > I did not mean this specific initialization method of proc_handler, i 
> > > meant pointers to functions in general.
> > There was an argument put forward by Alexy (I think) a while ago.  
> > That argued for the form without the address of operator.
> > The reason being that without it you can do:
> > #define proc_dointvec NULL
> > in a header when sysctl support it compiled out.  Using address of
> > you wind up with stub functions in sysctl.c to handle the case when
> > sysctl is compiled out.
> > It isn't a strong case but since not using & is also shorter and as 
> > Ingo pointed out more common I think no & wins.
> I can think of another reason as well: the & operator can be dangerous 
> if code is changed from functions to function pointers.
> 
> The short form:
> 
>   val = do_my_func;
> 
> will work just fine if 'my_func' is changed to a function pointer, as it 
> will evaluate to the value of the function pointer - i.e. the address of 
> the function.
> 
> The longer form:
> 
>   val = &do_my_func;
> 
> might break in a subtle way, because it will now become the address of 
> the function pointer - not the function address.
> 
> Combined the shortness, the NULL init, the function pointer invariance, 
> plus existing in-kernel practice all suggest that the short form should 
> be used.
> 
> ( i didnt want to turn this small issue into a long argument - it's just
>   that the code was going in the wrong direction. )

That sounds like something coccinelle would do well,
so I've cc'd Julia Lawall.

http://lkml.org/lkml/2009/11/15/55


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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 17:31             ` Joe Perches
@ 2009-11-15 18:20               ` Julia Lawall
  2009-11-15 19:23                 ` Joe Perches
  0 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2009-11-15 18:20 UTC (permalink / raw)
  To: Joe Perches
  Cc: Ingo Molnar, Eric W. Biederman, Am??rico Wang, LKML, Andrew Morton

On Sun, 15 Nov 2009, Joe Perches wrote:

> On Sun, 2009-11-15 at 11:33 +0100, Ingo Molnar wrote:
> > * Eric W. Biederman <ebiederm@xmission.com> wrote:
> > > Ingo Molnar <mingo@elte.hu> writes:
> > > > * Joe Perches <joe@perches.com> wrote:
> > > >> On Sun, 2009-11-15 at 09:11 +0100, Ingo Molnar wrote:
> > > >> > * Am??rico Wang <xiyou.wangcong@gmail.com> wrote:
> > > >> > > On Sat, Nov 14, 2009 at 05:52:05PM -0800, Joe Perches wrote:
> > > >> > > >Seems to be a typo.
> > > >> > > Acked-by: WANG Cong <xiyou.wangcong@gmail.com>
> > > >> > (Cc:-ed Eric who is running the sysctl tree these days)
> > > >> > Almost everywhere in the kernel we use the shorter version, so all of 
> > > >> > sysctl.c should eventually change to that variant.
> > > >> It's closer to 50/50, but it's 1 vs 133 in that file.
> > > >> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*&\s*\w+' * | wc -l
> > > >> 339
> > > >> $ grep -Pr --include=*.[ch] '\.proc_handler\s*=\s*[^&]\s*\w+' * | wc -l
> > > >> 432
> > > > I did not mean this specific initialization method of proc_handler, i 
> > > > meant pointers to functions in general.
> > > There was an argument put forward by Alexy (I think) a while ago.  
> > > That argued for the form without the address of operator.
> > > The reason being that without it you can do:
> > > #define proc_dointvec NULL
> > > in a header when sysctl support it compiled out.  Using address of
> > > you wind up with stub functions in sysctl.c to handle the case when
> > > sysctl is compiled out.
> > > It isn't a strong case but since not using & is also shorter and as 
> > > Ingo pointed out more common I think no & wins.
> > I can think of another reason as well: the & operator can be dangerous 
> > if code is changed from functions to function pointers.
> > 
> > The short form:
> > 
> >   val = do_my_func;
> > 
> > will work just fine if 'my_func' is changed to a function pointer, as it 
> > will evaluate to the value of the function pointer - i.e. the address of 
> > the function.
> > 
> > The longer form:
> > 
> >   val = &do_my_func;
> > 
> > might break in a subtle way, because it will now become the address of 
> > the function pointer - not the function address.
> > 
> > Combined the shortness, the NULL init, the function pointer invariance, 
> > plus existing in-kernel practice all suggest that the short form should 
> > be used.
> > 
> > ( i didnt want to turn this small issue into a long argument - it's just
> >   that the code was going in the wrong direction. )
> 
> That sounds like something coccinelle would do well,
> so I've cc'd Julia Lawall.
> 
> http://lkml.org/lkml/2009/11/15/55

Searching for things that are declared as functions (either a definition 
or a prototype), and then referenced as &f gives over 2000 results in 
almost 600 files.  Here are a couple of typical examples:

arch/arm/mach-omap1/clock.c:

static const struct clkops clkops_dspck = {
       .enable         = &omap1_clk_enable_dsp_domain,
       .disable        = &omap1_clk_disable_dsp_domain,
 };


arch/arm/mach-omap1/serial.c:

       ret = request_irq(gpio_to_irq(gpio_nr), &omap_serial_wake_interrupt,
                          IRQF_TRIGGER_RISING, "serial wakeup", NULL);

Should both cases lose the initial &?

julia

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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 18:20               ` Julia Lawall
@ 2009-11-15 19:23                 ` Joe Perches
  2009-11-15 20:40                   ` Julia Lawall
  0 siblings, 1 reply; 18+ messages in thread
From: Joe Perches @ 2009-11-15 19:23 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Ingo Molnar, Eric W. Biederman, Am??rico Wang, LKML, Andrew Morton

On Sun, 2009-11-15 at 19:20 +0100, Julia Lawall wrote:
> Searching for things that are declared as functions (either a definition 
> or a prototype), and then referenced as &f gives over 2000 results in 
> almost 600 files.

Just curious, do you know how many are referenced
without the &?

> Here are a couple of typical examples:
> 
> arch/arm/mach-omap1/clock.c:
> 
> static const struct clkops clkops_dspck = {
>        .enable         = &omap1_clk_enable_dsp_domain,
>        .disable        = &omap1_clk_disable_dsp_domain,
>  };
> 
> arch/arm/mach-omap1/serial.c:
> 
>        ret = request_irq(gpio_to_irq(gpio_nr), &omap_serial_wake_interrupt,
>                           IRQF_TRIGGER_RISING, "serial wakeup", NULL);
> 
> Should both cases lose the initial &?

If what is desired is kernel wide consistent use, yes.
What I would like is file/subsystem consistent use.

Looking at sysctl.c and seeing that different use
stand out was odd.


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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 19:23                 ` Joe Perches
@ 2009-11-15 20:40                   ` Julia Lawall
  2009-11-15 20:53                     ` Arnd Bergmann
  2009-11-15 21:13                     ` Joe Perches
  0 siblings, 2 replies; 18+ messages in thread
From: Julia Lawall @ 2009-11-15 20:40 UTC (permalink / raw)
  To: Joe Perches
  Cc: Ingo Molnar, Eric W. Biederman, Am??rico Wang, LKML, Andrew Morton

On Sun, 15 Nov 2009, Joe Perches wrote:

> On Sun, 2009-11-15 at 19:20 +0100, Julia Lawall wrote:
> > Searching for things that are declared as functions (either a definition 
> > or a prototype), and then referenced as &f gives over 2000 results in 
> > almost 600 files.
> 
> Just curious, do you know how many are referenced
> without the &?

I got over 95000 (not checked in detail, though).

> > Here are a couple of typical examples:
> > 
> > arch/arm/mach-omap1/clock.c:
> > 
> > static const struct clkops clkops_dspck = {
> >        .enable         = &omap1_clk_enable_dsp_domain,
> >        .disable        = &omap1_clk_disable_dsp_domain,
> >  };
> > 
> > arch/arm/mach-omap1/serial.c:
> > 
> >        ret = request_irq(gpio_to_irq(gpio_nr), &omap_serial_wake_interrupt,
> >                           IRQF_TRIGGER_RISING, "serial wakeup", NULL);
> > 
> > Should both cases lose the initial &?
> 
> If what is desired is kernel wide consistent use, yes.
> What I would like is file/subsystem consistent use.
> 
> Looking at sysctl.c and seeing that different use
> stand out was odd.

It would be possible to count the number of occurrences in a given file, 
and then change the ones that have the less popular format, or a format 
that occurs less than some percentage of time.

julia

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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 20:40                   ` Julia Lawall
@ 2009-11-15 20:53                     ` Arnd Bergmann
  2009-11-15 22:54                       ` Julia Lawall
  2009-11-15 21:13                     ` Joe Perches
  1 sibling, 1 reply; 18+ messages in thread
From: Arnd Bergmann @ 2009-11-15 20:53 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Joe Perches, Ingo Molnar, Eric W. Biederman, Am??rico Wang, LKML,
	Andrew Morton

On Sunday 15 November 2009 20:40:25 Julia Lawall wrote:
> It would be possible to count the number of occurrences in a given file, 
> and then change the ones that have the less popular format, or a format 
> that occurs less than some percentage of time.

How many of the 600 files use both formats?

	Arnd <><

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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 20:40                   ` Julia Lawall
  2009-11-15 20:53                     ` Arnd Bergmann
@ 2009-11-15 21:13                     ` Joe Perches
  2009-11-15 21:34                       ` Julia Lawall
  1 sibling, 1 reply; 18+ messages in thread
From: Joe Perches @ 2009-11-15 21:13 UTC (permalink / raw)
  To: Julia Lawall, Andy Whitcroft
  Cc: Ingo Molnar, Eric W. Biederman, Am??rico Wang, LKML, Andrew Morton

On Sun, 2009-11-15 at 21:40 +0100, Julia Lawall wrote:
> On Sun, 15 Nov 2009, Joe Perches wrote:
> > On Sun, 2009-11-15 at 19:20 +0100, Julia Lawall wrote:
> > > Searching for things that are declared as functions (either a definition 
> > > or a prototype), and then referenced as &f gives over 2000 results in 
> > > almost 600 files.
> > Just curious, do you know how many are referenced
> > without the &?
> I got over 95000 (not checked in detail, though).

Thanks.

I think that ~25+:1 ratio makes a good case for an
eventual conversion of the remaining uses.

> > If what is desired is kernel wide consistent use, yes.
> > What I would like is file/subsystem consistent use.
> > 
> > Looking at sysctl.c and seeing that different use
> > stand out was odd.
> 
> It would be possible to count the number of occurrences in a given file, 
> and then change the ones that have the less popular format, or a format 
> that occurs less than some percentage of time.

Maybe it'd be useful to add a coccinelle/spatch
directory in scripts and add these scripts so
that files and subsystems can updated over time.

I can not find a directory of coccinelle input
scripts for linux at:
http://coccinelle.lip6.fr/download.php
Is there a list somewhere?

Perhaps add a checkpatch test as well though
that might be an interesting test to write in
perl.



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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 21:13                     ` Joe Perches
@ 2009-11-15 21:34                       ` Julia Lawall
  0 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2009-11-15 21:34 UTC (permalink / raw)
  To: Joe Perches
  Cc: Andy Whitcroft, Ingo Molnar, Eric W. Biederman, Am??rico Wang,
	LKML, Andrew Morton

On Sun, 15 Nov 2009, Joe Perches wrote:

> On Sun, 2009-11-15 at 21:40 +0100, Julia Lawall wrote:
> > On Sun, 15 Nov 2009, Joe Perches wrote:
> > > On Sun, 2009-11-15 at 19:20 +0100, Julia Lawall wrote:
> > > > Searching for things that are declared as functions (either a definition 
> > > > or a prototype), and then referenced as &f gives over 2000 results in 
> > > > almost 600 files.
> > > Just curious, do you know how many are referenced
> > > without the &?
> > I got over 95000 (not checked in detail, though).
> 
> Thanks.
> 
> I think that ~25+:1 ratio makes a good case for an
> eventual conversion of the remaining uses.

OK, I will try to look into it sometime soon.

> > > If what is desired is kernel wide consistent use, yes.
> > > What I would like is file/subsystem consistent use.
> > > 
> > > Looking at sysctl.c and seeing that different use
> > > stand out was odd.
> > 
> > It would be possible to count the number of occurrences in a given file, 
> > and then change the ones that have the less popular format, or a format 
> > that occurs less than some percentage of time.
> 
> Maybe it'd be useful to add a coccinelle/spatch
> directory in scripts and add these scripts so
> that files and subsystems can updated over time.
> 
> I can not find a directory of coccinelle input
> scripts for linux at:
> http://coccinelle.lip6.fr/download.php
> Is there a list somewhere?

At the bottom of the download page there is a tool called coccicheck that 
runs Coccinelle on a set of semantic patches.  It comes with a set of 
examples.

http://coccinelle.lip6.fr/distrib/coccicheck-0.1.tgz

julia

> Perhaps add a checkpatch test as well though
> that might be an interesting test to write in
> perl.
> 
> 
> 

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

* Re: [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec,
  2009-11-15 20:53                     ` Arnd Bergmann
@ 2009-11-15 22:54                       ` Julia Lawall
  0 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2009-11-15 22:54 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Joe Perches, Ingo Molnar, Eric W. Biederman, Am??rico Wang, LKML,
	Andrew Morton

On Sun, 15 Nov 2009, Arnd Bergmann wrote:

> On Sunday 15 November 2009 20:40:25 Julia Lawall wrote:
> > It would be possible to count the number of occurrences in a given file, 
> > and then change the ones that have the less popular format, or a format 
> > that occurs less than some percentage of time.
> 
> How many of the 600 files use both formats?

This time I considered only cases where the function is defined in the 
same file, not where the function is presented only as a prototype.  I 
get:

502 files that use both options
83 files that only use & for function pointers
9374 files that never use & for function pointers

(Only files that use at least one of the options are considered.)

julia

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

end of thread, other threads:[~2009-11-15 22:54 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-15  1:52 [PATCH] sysctl.c: Change a .proc_handler = proc_dointvec to &proc_dointvec, Joe Perches
2009-11-15  6:59 ` Américo Wang
2009-11-15  8:11   ` Ingo Molnar
2009-11-15  8:28     ` Joe Perches
2009-11-15  8:39       ` Ingo Molnar
2009-11-15 10:04         ` Eric W. Biederman
2009-11-15 10:33           ` Ingo Molnar
2009-11-15 12:29             ` Eric W. Biederman
2009-11-15 13:57               ` Ingo Molnar
2009-11-15 14:14                 ` Eric W. Biederman
2009-11-15 17:31             ` Joe Perches
2009-11-15 18:20               ` Julia Lawall
2009-11-15 19:23                 ` Joe Perches
2009-11-15 20:40                   ` Julia Lawall
2009-11-15 20:53                     ` Arnd Bergmann
2009-11-15 22:54                       ` Julia Lawall
2009-11-15 21:13                     ` Joe Perches
2009-11-15 21:34                       ` Julia Lawall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.