[PATCH v9 5/6] scanf: tidy header `#include`s

Tamir Duberstein posted 6 patches 9 months, 1 week ago
[PATCH v9 5/6] scanf: tidy header `#include`s
Posted by Tamir Duberstein 9 months, 1 week ago
Remove the unused `kernel.h`. Replace `string.h` with `sprintf.h` as the
former doesn't seem to be used directly.

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 lib/tests/scanf_kunit.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/tests/scanf_kunit.c b/lib/tests/scanf_kunit.c
index e9a36ed80575..d96d7ca85b52 100644
--- a/lib/tests/scanf_kunit.c
+++ b/lib/tests/scanf_kunit.c
@@ -5,12 +5,11 @@
 
 #include <kunit/test.h>
 #include <linux/bitops.h>
-#include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/overflow.h>
 #include <linux/prandom.h>
 #include <linux/slab.h>
-#include <linux/string.h>
+#include <linux/sprintf.h>
 
 #define BUF_SIZE 1024
 

-- 
2.48.1
Re: [PATCH v9 5/6] scanf: tidy header `#include`s
Posted by Petr Mladek 9 months ago
On Fri 2025-03-07 06:27:38, Tamir Duberstein wrote:
> Remove the unused `kernel.h`. Replace `string.h` with `sprintf.h` as the
> former doesn't seem to be used directly.

> --- a/lib/tests/scanf_kunit.c
> +++ b/lib/tests/scanf_kunit.c
> @@ -5,12 +5,11 @@
>  
>  #include <kunit/test.h>
>  #include <linux/bitops.h>
> -#include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/overflow.h>
>  #include <linux/prandom.h>
>  #include <linux/slab.h>
> -#include <linux/string.h>
> +#include <linux/sprintf.h>
>  
>  #define BUF_SIZE 1024
>  


The change makes sense and looks good to me. I would go with it.

Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>

Further improvements might be done later in a separate patchset...

Best Regards,
Petr
Re: [PATCH v9 5/6] scanf: tidy header `#include`s
Posted by Andy Shevchenko 9 months, 1 week ago
On Fri, Mar 07, 2025 at 06:27:38AM -0500, Tamir Duberstein wrote:
> Remove the unused `kernel.h`. Replace `string.h` with `sprintf.h` as the
> former doesn't seem to be used directly.

...

>  #include <kunit/test.h>

+ array_size.h

>  #include <linux/bitops.h>

+ bug.h // BUILD_BUG_ON()
+ errno.h // actually asm/errno.h, but in C code the linux/* will suffice

> -#include <linux/kernel.h>

This was used like a "proxy" header to a lot, see around.

>  #include <linux/module.h>
>  #include <linux/overflow.h>
>  #include <linux/prandom.h>
>  #include <linux/slab.h>
> -#include <linux/string.h>
> +#include <linux/sprintf.h>

+ types.h // u32, __scanf, ...

...

Note,the above I made based on the context of your changes, I haven't checked
the resulting file in full, please do it yourself.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v9 5/6] scanf: tidy header `#include`s
Posted by Andy Shevchenko 9 months, 1 week ago
On Fri, Mar 07, 2025 at 07:34:29PM +0200, Andy Shevchenko wrote:
> On Fri, Mar 07, 2025 at 06:27:38AM -0500, Tamir Duberstein wrote:

...

> >  #include <kunit/test.h>
> 
> + array_size.h
> 
> >  #include <linux/bitops.h>

> + bug.h // BUILD_BUG_ON()

Actually if it's only BUILD_BUG_ON(), then we better use build_bug.h.

> + errno.h // actually asm/errno.h, but in C code the linux/* will suffice
> 
> > -#include <linux/kernel.h>
> 
> This was used like a "proxy" header to a lot, see around.
> 
> >  #include <linux/module.h>
> >  #include <linux/overflow.h>
> >  #include <linux/prandom.h>
> >  #include <linux/slab.h>
> > -#include <linux/string.h>
> > +#include <linux/sprintf.h>
> 
> + types.h // u32, __scanf, ...

...

> Note,the above I made based on the context of your changes, I haven't checked
> the resulting file in full, please do it yourself.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v9 5/6] scanf: tidy header `#include`s
Posted by Tamir Duberstein 9 months, 1 week ago
On Fri, Mar 7, 2025 at 12:40 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Fri, Mar 07, 2025 at 07:34:29PM +0200, Andy Shevchenko wrote:
> > On Fri, Mar 07, 2025 at 06:27:38AM -0500, Tamir Duberstein wrote:
>
> ...
>
> > >  #include <kunit/test.h>
> >
> > + array_size.h
> >
> > >  #include <linux/bitops.h>
>
> > + bug.h // BUILD_BUG_ON()
>
> Actually if it's only BUILD_BUG_ON(), then we better use build_bug.h.
>
> > + errno.h // actually asm/errno.h, but in C code the linux/* will suffice
> >
> > > -#include <linux/kernel.h>
> >
> > This was used like a "proxy" header to a lot, see around.
> >
> > >  #include <linux/module.h>
> > >  #include <linux/overflow.h>
> > >  #include <linux/prandom.h>
> > >  #include <linux/slab.h>
> > > -#include <linux/string.h>
> > > +#include <linux/sprintf.h>
> >
> > + types.h // u32, __scanf, ...
>
> ...
>
> > Note,the above I made based on the context of your changes, I haven't checked
> > the resulting file in full, please do it yourself.
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

If it's easier to take this series without this patch, please do so --
my tools aren't giving me any help with IWYU and I'm not familiar
enough with the kernel to do a thorough manual job. As this is not
core to the goals of this series, I'd prefer not to hold it up over
it.

Thanks.

Tamir