linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* cocci script hints request
@ 2021-04-13  9:04 Fabio Aiuto
  2021-04-13  9:11 ` Greg KH
  2021-04-13  9:56 ` Julia Lawall
  0 siblings, 2 replies; 6+ messages in thread
From: Fabio Aiuto @ 2021-04-13  9:04 UTC (permalink / raw)
  To: gregkh, joe, julia.lawall; +Cc: linux-staging, linux-kernel

Hi,

I would like to improve the following coccinelle script:

@@
expression a, fmt;
expression list var_args;
@@

-       DBG_871X_LEVEL(a, fmt, var_args);
+       printk(fmt, var_args);

I would  replace the DBG_871X_LEVEL macro with printk, but
I can't find a way to add KERN_* constant prefix to the fmt
argument in the + code line. If i try this

@@
expression a, fmt;
expression list var_args;
@@

-       DBG_871X_LEVEL(a, fmt, var_args);
+       printk(KERN_DEBUG fmt, var_args);

plus: parse error: 
  File "../test.cocci", line 94, column 20, charpos = 1171
  around = 'fmt',
  whole content = +	printk(KERN_DEBUG fmt, var_args);

how could I do this?

thank you in advance,

fabio

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

* Re: cocci script hints request
  2021-04-13  9:04 cocci script hints request Fabio Aiuto
@ 2021-04-13  9:11 ` Greg KH
  2021-04-13  9:24   ` Fabio Aiuto
  2021-04-13  9:56 ` Julia Lawall
  1 sibling, 1 reply; 6+ messages in thread
From: Greg KH @ 2021-04-13  9:11 UTC (permalink / raw)
  To: Fabio Aiuto; +Cc: joe, julia.lawall, linux-staging, linux-kernel

On Tue, Apr 13, 2021 at 11:04:01AM +0200, Fabio Aiuto wrote:
> Hi,
> 
> I would like to improve the following coccinelle script:
> 
> @@
> expression a, fmt;
> expression list var_args;
> @@
> 
> -       DBG_871X_LEVEL(a, fmt, var_args);
> +       printk(fmt, var_args);
> 
> I would  replace the DBG_871X_LEVEL macro with printk,

No you really do not, you want to change that to a dev_*() call instead
depending on the "level" of the message.

No "raw" printk() calls please, I will just reject them :)

thanks,

greg k-h

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

* Re: cocci script hints request
  2021-04-13  9:11 ` Greg KH
@ 2021-04-13  9:24   ` Fabio Aiuto
  2021-04-13  9:42     ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Fabio Aiuto @ 2021-04-13  9:24 UTC (permalink / raw)
  To: Greg KH; +Cc: joe, julia.lawall, linux-staging, linux-kernel

On Tue, Apr 13, 2021 at 11:11:38AM +0200, Greg KH wrote:
> On Tue, Apr 13, 2021 at 11:04:01AM +0200, Fabio Aiuto wrote:
> > Hi,
> > 
> > I would like to improve the following coccinelle script:
> > 
> > @@
> > expression a, fmt;
> > expression list var_args;
> > @@
> > 
> > -       DBG_871X_LEVEL(a, fmt, var_args);
> > +       printk(fmt, var_args);
> > 
> > I would  replace the DBG_871X_LEVEL macro with printk,
> 
> No you really do not, you want to change that to a dev_*() call instead
> depending on the "level" of the message.
> 
> No "raw" printk() calls please, I will just reject them :)
> 
> thanks,
> 
> greg k-h

but there are very few occurences of DBG_871X_LEVEL in module init functions:

static int __init rtw_drv_entry(void)
{
        int ret;

        DBG_871X_LEVEL(_drv_always_, "module init start\n");
        dump_drv_version(RTW_DBGDUMP);
#ifdef BTCOEXVERSION
        DBG_871X_LEVEL(_drv_always_, "rtl8723bs BT-Coex version = %s\n", BTCOEXVERSION);
#endif /*  BTCOEXVERSION */

        sdio_drvpriv.drv_registered = true;

        ret = sdio_register_driver(&sdio_drvpriv.r871xs_drv);
        if (ret != 0) {
                sdio_drvpriv.drv_registered = false;
                rtw_ndev_notifier_unregister();
        }

        DBG_871X_LEVEL(_drv_always_, "module init ret =%d\n", ret);
        return ret;
}

where I don't have a device available... shall I pass NULL to
first argument?

Another question: may I use netdev_dbg in case of rtl8723bs?

thank you,

fabio

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

* Re: cocci script hints request
  2021-04-13  9:24   ` Fabio Aiuto
@ 2021-04-13  9:42     ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2021-04-13  9:42 UTC (permalink / raw)
  To: Fabio Aiuto; +Cc: joe, julia.lawall, linux-staging, linux-kernel

On Tue, Apr 13, 2021 at 11:24:56AM +0200, Fabio Aiuto wrote:
> On Tue, Apr 13, 2021 at 11:11:38AM +0200, Greg KH wrote:
> > On Tue, Apr 13, 2021 at 11:04:01AM +0200, Fabio Aiuto wrote:
> > > Hi,
> > > 
> > > I would like to improve the following coccinelle script:
> > > 
> > > @@
> > > expression a, fmt;
> > > expression list var_args;
> > > @@
> > > 
> > > -       DBG_871X_LEVEL(a, fmt, var_args);
> > > +       printk(fmt, var_args);
> > > 
> > > I would  replace the DBG_871X_LEVEL macro with printk,
> > 
> > No you really do not, you want to change that to a dev_*() call instead
> > depending on the "level" of the message.
> > 
> > No "raw" printk() calls please, I will just reject them :)
> > 
> > thanks,
> > 
> > greg k-h
> 
> but there are very few occurences of DBG_871X_LEVEL in module init functions:

Then do those "by hand", if they really are needed.

Drivers, when they are working properly, are totally quiet.

> 
> static int __init rtw_drv_entry(void)
> {
>         int ret;
> 
>         DBG_871X_LEVEL(_drv_always_, "module init start\n");

Horrible, please remove.

>         dump_drv_version(RTW_DBGDUMP);
> #ifdef BTCOEXVERSION
>         DBG_871X_LEVEL(_drv_always_, "rtl8723bs BT-Coex version = %s\n", BTCOEXVERSION);

Not needed at all.

> #endif /*  BTCOEXVERSION */
> 
>         sdio_drvpriv.drv_registered = true;
> 
>         ret = sdio_register_driver(&sdio_drvpriv.r871xs_drv);
>         if (ret != 0) {
>                 sdio_drvpriv.drv_registered = false;
>                 rtw_ndev_notifier_unregister();
>         }
> 
>         DBG_871X_LEVEL(_drv_always_, "module init ret =%d\n", ret);

Again, not needed this is noise and if someone really needs to debug
this, they can use the built-in kernel ftrace logic instead.

>         return ret;
> }
> 
> where I don't have a device available... shall I pass NULL to
> first argument?

No, that would be a mess :)

I bet almost all of these can be removed if they are like the above
examples as we do not need a lot of "look, the code got here!" type of
messages at all.

> Another question: may I use netdev_dbg in case of rtl8723bs?

Yes please, that is even better and recommended.

thanks,

greg k-h

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

* Re: cocci script hints request
  2021-04-13  9:04 cocci script hints request Fabio Aiuto
  2021-04-13  9:11 ` Greg KH
@ 2021-04-13  9:56 ` Julia Lawall
  2021-04-13 10:07   ` Fabio Aiuto
  1 sibling, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2021-04-13  9:56 UTC (permalink / raw)
  To: Fabio Aiuto; +Cc: gregkh, joe, linux-staging, linux-kernel



On Tue, 13 Apr 2021, Fabio Aiuto wrote:

> Hi,
>
> I would like to improve the following coccinelle script:
>
> @@
> expression a, fmt;
> expression list var_args;
> @@
>
> -       DBG_871X_LEVEL(a, fmt, var_args);
> +       printk(fmt, var_args);
>
> I would  replace the DBG_871X_LEVEL macro with printk, but
> I can't find a way to add KERN_* constant prefix to the fmt
> argument in the + code line. If i try this
>
> @@
> expression a, fmt;
> expression list var_args;
> @@
>
> -       DBG_871X_LEVEL(a, fmt, var_args);
> +       printk(KERN_DEBUG fmt, var_args);
>
> plus: parse error:
>   File "../test.cocci", line 94, column 20, charpos = 1171
>   around = 'fmt',
>   whole content = +	printk(KERN_DEBUG fmt, var_args);
>
> how could I do this?

Although I certainly agree with Greg, I'll answer the question from a
technical point of view.

I'm not sure that that kind of compound string is supported for a
metavariable.  It is possible to get around this problem using a python
script.  If you ever need to do this for a better reason, you can take a
look at demos/pythontococci.cocci in the Coccinelle source code
distribution.

julia

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

* Re: cocci script hints request
  2021-04-13  9:56 ` Julia Lawall
@ 2021-04-13 10:07   ` Fabio Aiuto
  0 siblings, 0 replies; 6+ messages in thread
From: Fabio Aiuto @ 2021-04-13 10:07 UTC (permalink / raw)
  To: Julia Lawall; +Cc: gregkh, joe, linux-staging, linux-kernel

On Tue, Apr 13, 2021 at 11:56:20AM +0200, Julia Lawall wrote:
> 
> 
> On Tue, 13 Apr 2021, Fabio Aiuto wrote:
> 
> > Hi,
> >
> > I would like to improve the following coccinelle script:
> >
> > @@
> > expression a, fmt;
> > expression list var_args;
> > @@
> >
> > -       DBG_871X_LEVEL(a, fmt, var_args);
> > +       printk(fmt, var_args);
> >
> > I would  replace the DBG_871X_LEVEL macro with printk, but
> > I can't find a way to add KERN_* constant prefix to the fmt
> > argument in the + code line. If i try this
> >
> > @@
> > expression a, fmt;
> > expression list var_args;
> > @@
> >
> > -       DBG_871X_LEVEL(a, fmt, var_args);
> > +       printk(KERN_DEBUG fmt, var_args);
> >
> > plus: parse error:
> >   File "../test.cocci", line 94, column 20, charpos = 1171
> >   around = 'fmt',
> >   whole content = +	printk(KERN_DEBUG fmt, var_args);
> >
> > how could I do this?
> 
> Although I certainly agree with Greg, I'll answer the question from a
> technical point of view.
> 
> I'm not sure that that kind of compound string is supported for a
> metavariable.  It is possible to get around this problem using a python
> script.  If you ever need to do this for a better reason, you can take a
> look at demos/pythontococci.cocci in the Coccinelle source code
> distribution.
> 
> julia

thank you, this helps a lot!

fabio

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

end of thread, other threads:[~2021-04-13 10:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13  9:04 cocci script hints request Fabio Aiuto
2021-04-13  9:11 ` Greg KH
2021-04-13  9:24   ` Fabio Aiuto
2021-04-13  9:42     ` Greg KH
2021-04-13  9:56 ` Julia Lawall
2021-04-13 10:07   ` Fabio Aiuto

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