ACPI: processor: idle: Replace strlcat() with better alternative
PATCH 1/1 ACPI: processor: idle: Replace strlcat() with better alternative
strlcpy() and strlcat() are confusing APIs and the former one already gone from the kernel. In preparation to kill strlcat() replace it with the better alternative.
--- drivers/acpi/processor_idle.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/acpi/processor_idle.c +1 -3
@@ -1010,9 +1010,7 @@ static bool combine_lpi_states(struct acpi_lpi_state *local, result->arch_flags = parent->arch_flags; result->index = parent->index; -strscpy (result->desc, local->desc,ACPI_CX_DESC_LEN ); -strlcat (result->desc,"+" ,ACPI_CX_DESC_LEN ); -strlcat (result->desc, parent->desc,ACPI_CX_DESC_LEN ); +snprintf (result->desc,ACPI_CX_DESC_LEN ,"%s+%s" , local->desc, parent->desc);return true; }
Signature · 1 line
2.50.1
Quoted 14 lines · Andy Shevchenko
strlcpy()andstrlcat()are confusing APIs and the former one already gone from the kernel. In preparation to killstrlcat()replace it with the better alternative.Signed-off-by Andy Shevchenko <[email protected]>---
drivers/acpi/processor_idle.c| 4 +---1 file changed, 1 insertion(+), 3 deletions(-)drivers/acpi/processor_idle.c +0
-0
drivers/acpi/processor_idle.c static bool combine_lpi_states(struct acpi_lpi_state *local, · line 1016
Quoted 10 lines
drivers/acpi/processor_idle.c +1
-3@@ -1010,9 +1010,7 @@ static bool combine_lpi_states(struct acpi_lpi_state *local, result->arch_flags = parent->arch_flags; result->index = parent->index; -strscpy (result->desc, local->desc,ACPI_CX_DESC_LEN ); -strlcat (result->desc,"+" ,ACPI_CX_DESC_LEN ); -strlcat (result->desc, parent->desc,ACPI_CX_DESC_LEN ); +snprintf (result->desc,ACPI_CX_DESC_LEN ,"%s+%s" , local->desc, parent->desc);return true; }
Is this patch in relation to my string.c patch? You would have to do this for about 120~ files.
V/R
Josh Law
Quoted 6 lines · Josh Law
Quoted 3 lines · Andy Shevchenko
strlcpy()andstrlcat()are confusing APIs and the former one already gone from the kernel. In preparation to killstrlcat()replace it with the better alternative.Is this patch in relation to my
string.cpatch?
Yes.
Quoted 1 line
You would have to do this for about 120~ files.
Not me, just showing you what to do.
Btw, what kind of assistance do you use for the patches?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Josh Law
Quoted 3 lines · Andy Shevchenko
strlcpy()andstrlcat()are confusing APIs and the former one already gone from the kernel. In preparation to killstrlcat()replace it with the better alternative.Is this patch in relation to my
string.cpatch?
Quoted 9 lines
Yes.
Quoted 1 line
You would have to do this for about 120~ files.
Not me, just showing you what to do.
Btw, what kind of assistance do you use for the patches?
None
I use grep to find all the files calling the functions (took a while!)
And if I did those patches, I can't guarantee all of them will be ACKed.
V/R
Josh Law
Quoted 11 lines · Josh Law
Quoted 10 lines · Andy Shevchenko
Quoted 6 lines · Josh Law
Quoted 3 lines · Andy Shevchenko
strlcpy()andstrlcat()are confusing APIs and the former one already gone from the kernel. In preparation to killstrlcat()replace it with the better alternative.Is this patch in relation to my
string.cpatch?Yes.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
You would have to do this for about 120~ files.
Not me, just showing you what to do.
Btw, what kind of assistance do you use for the patches?
None
Hmm... Many patches that are generated require quite a lot of time investment and understanding the code. It's unbelievable that a person can do that without an assistance.
Quoted 1 line
I use grep to find all the files calling the functions (took a while!)
No, that's not what I was asking about.
Quoted 1 line
And if I did those patches, I can't guarantee all of them will be ACKed.
Interesting way of saying the obvious. And if you didn't?..
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 24 lines · Andy Shevchenko
Quoted 11 lines · Josh Law
Quoted 10 lines · Andy Shevchenko
Quoted 6 lines · Josh Law
Quoted 3 lines · Andy Shevchenko
strlcpy()andstrlcat()are confusing APIs and the former one already gone from the kernel. In preparation to killstrlcat()replace it with the better alternative.Is this patch in relation to my
string.cpatch?Yes.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
You would have to do this for about 120~ files.
Not me, just showing you what to do.
Btw, what kind of assistance do you use for the patches?
None
Hmm... Many patches that are generated require quite a lot of time investment and understanding the code. It's unbelievable that a person can do that without an assistance.
Quoted 8 lines
Quoted 1 line
I use grep to find all the files calling the functions (took a while!)
No, that's not what I was asking about.
Quoted 1 line
And if I did those patches, I can't guarantee all of them will be ACKed.
Interesting way of saying the obvious. And if you didn't?..
I understand your suspicion, my commit descriptions are written by a LLM, but the actual code itself is mine, the reason why I do commit descriptions with AI, is because I'm not the "sharpest tool in the shed" with writing descriptions for anything! If I add a feature, I can't do much writing about it, and I worry that if I can't explain a feature well, it won't get merged. I'm sorry for all the confusion, also. The reason I do high volume of patches is quite simple.
I love lib/ basically, it's my favourite directory to work on, For various reasons, and I have quite high work energy for my "passions", sorry if you think I use assistance for everything (I don't, only for commit descriptions), I will slow down from now on with the patches.
And from now on I will try to manually write descriptions (even though I'm not the best at writing anything, even if I understand it heavily)
V/R
Josh Law
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Andy,
kernel test robot noticed the following build warnings:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on rafael-pm/bleeding-edge linus/master v7.0-rc4 next-20260316] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/ACPI-processor-idle-Replace-strlcat-with-better-alternative/20260317-014800 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next patch link: https://lore.kernel.org/r/20260316170158.1596857-1-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v1 1/1] ACPI: processor: idle: Replace strlcat() with better alternative config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20260317/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260317/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/acpi/processor_idle.c: In function 'flatten_lpi_states':
>> drivers/acpi/processor_idle.c:1013:56: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
1013 | snprintf(result->desc, ACPI_CX_DESC_LEN, "%s+%s", local->desc, parent->desc);
| ^
In function 'combine_lpi_states',
inlined from 'flatten_lpi_states' at drivers/acpi/processor_idle.c:1059:8:
drivers/acpi/processor_idle.c:1013:9: note: 'snprintf' output 2 or more bytes (assuming 33) into a destination of size 32
1013 | snprintf(result->desc, ACPI_CX_DESC_LEN, "%s+%s", local->desc, parent->desc);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~vim +/snprintf +1013 drivers/acpi/processor_idle.c
984
985 /**
986 * combine_lpi_states - combine local and parent LPI states to form a composite LPI state
987 *
988 * @local: local LPI state
989 * @parent: parent LPI state
990 * @result: composite LPI state
991 */
992 static bool combine_lpi_states(struct acpi_lpi_state *local,
993 struct acpi_lpi_state *parent,
994 struct acpi_lpi_state *result)
995 {
996 if (parent->entry_method == ACPI_CSTATE_INTEGER) {
997 if (!parent->address) /* 0 means autopromotable */
998 return false;
999 result->address = local->address + parent->address;
1000 } else {
1001 result->address = parent->address;
1002 }
1003
1004 result->min_residency = max(local->min_residency, parent->min_residency);
1005 result->wake_latency = local->wake_latency + parent->wake_latency;
1006 result->enable_parent_state = parent->enable_parent_state;
1007 result->entry_method = local->entry_method;
1008
1009 result->flags = parent->flags;
1010 result->arch_flags = parent->arch_flags;
1011 result->index = parent->index;
1012
> 1013 snprintf(result->desc, ACPI_CX_DESC_LEN, "%s+%s", local->desc, parent->desc);
1014 return true;
1015 }
1016
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 18 lines · kernel test robot
Hi Andy,
kernel test robot noticed the following build warnings:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on rafael-pm/bleeding-edge linus/master v7.0-rc4 next-20260316] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/ACPI-processor-idle-Replace-strlcat-with-better-alternative/20260317-014800 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next patch link: https://lore.kernel.org/r/20260316170158.1596857-1-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v1 1/1] ACPI: processor: idle: Replace strlcat() with better alternative config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20260317/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260317/[email protected]/reproduce)
Quoted 4 lines
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Yes, thanks, I already sent a v2 before getting this report.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 3 lines · Andy Shevchenko
strlcpy()andstrlcat()are confusing APIs and the former one already gone from the kernel. In preparation to killstrlcat()replace it with the better alternative.
Yes please. There are a few places I looked at in the past that might benefit from being changed to seq_buf or similar (where snprintf doesn't cut it), but otherwise the removal of strlcat should be straight forward and would be well appreciated. :)
Quoted 2 lines
Signed-off-by Andy Shevchenko <[email protected]>
-Kees
Quoted 22 lines
--- drivers/acpi/processor_idle.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/acpi/processor_idle.c +1
-3@@ -1010,9 +1010,7 @@ static bool combine_lpi_states(struct acpi_lpi_state *local, result->arch_flags = parent->arch_flags; result->index = parent->index; -strscpy (result->desc, local->desc,ACPI_CX_DESC_LEN ); -strlcat (result->desc,"+" ,ACPI_CX_DESC_LEN ); -strlcat (result->desc, parent->desc,ACPI_CX_DESC_LEN ); +snprintf (result->desc,ACPI_CX_DESC_LEN ,"%s+%s" , local->desc, parent->desc);return true; }Signature · 1 line
2.50.1
Signature · 1 line
Kees Cook
Quoted 9 lines · Kees Cook
Quoted 3 lines · Andy Shevchenko
strlcpy()andstrlcat()are confusing APIs and the former one already gone from the kernel. In preparation to killstrlcat()replace it with the better alternative.Yes please. There are a few places I looked at in the past that might benefit from being changed to
seq_bufor similar (where snprintf doesn't cut it), but otherwise the removal of strlcat should be straight forward and would be well appreciated. :)
Thank you for confirming, this is basically the message to Josh to find users and start converting them and kill strlcat() eventually. Josh, as you see it will be well appreciated!
Quoted 3 lines
Quoted 1 line
Signed-off-by Andy Shevchenko <[email protected]>Reviewed-by Kees Cook <[email protected]>
Thanks! There was a v2 which Rafael already accepted where scnprintf() is used due to GCC complains about snprintf() potential string cuts.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Thanks! There was a v2 which Rafael already accepted where
scnprintf()is used due to GCC complains aboutsnprintf()potential string cuts.
Oops, yes, I see that now. Looks good!
Signature · 1 line
Kees Cook
Quoted 5 lines
Thank you for confirming, this is basically the message to Josh to find users and start converting them and kill
strlcat()eventually. Josh, as you see it will be well appreciated!
Thank you! But the only reason I'm not doing it is because if I submit all of the patches, let's say, 50 gets merged (including strings.c) and like 50 don't, then 50 will have a nonexistent/slow API because they chose to not merge my patch
Quoted 10 lines · Josh Law
Quoted 5 lines
Thank you for confirming, this is basically the message to Josh to find users and start converting them and kill
strlcat()eventually. Josh, as you see it will be well appreciated!Thank you! But the only reason I'm not doing it is because if I submit all of the patches, let's say, 50 gets merged (including
strings.c) and like 50 don't, then 50 will have a nonexistent/slow API because they chose to not merge my patch
Huh?! Even if you do 50%, it will still be appreciated as it's not a job that has to be done in one cycle. Also we expect to have a constructive feedback from the maintainers. Killing an old and confusing API is a good justification and it will be rare maintainer even thinking to tell against. The feedback may be given to the implementation and how to improve or adjust, but believe close to 0 maintainers will say a word against dropping strlcat().
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Kees Cook
Quoted 3 lines · Andy Shevchenko
strlcpy()andstrlcat()are confusing APIs and the former one already gone from the kernel. In preparation to killstrlcat()replace it with the better alternative.
Quoted 8 lines
Quoted 4 lines
Yes please. There are a few places I looked at in the past that might benefit from being changed to
seq_bufor similar (where snprintf doesn't cut it), but otherwise the removal of strlcat should be straight forward and would be well appreciated. :)Thank you for confirming, this is basically the message to Josh to find users and start converting them and kill
strlcat()eventually. Josh, as you see it will be well appreciated!
As an example of a seq_buf user, see block/partitions/core.c:
static struct parsed_partitions *check_partition(struct gendisk *hd)
{
...
state->pp_buf = (char *)__get_free_page(GFP_KERNEL);
...
state->pp_buf[0] = '\0';
...
snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name);
...
while (!res && check_part[i]) {
...
res = check_part[i++](state);...
All the partition handlers then use strlcat to append more details, and it's totally unbounded. The correct thing would be to build a seq_buf to attach to state instead of the pp_buf, and the handlers would use seq_buf functions to append their info, etc etc.
-Kees
Signature · 1 line
Kees Cook
Quoted 30 lines · Kees Cook
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Kees Cook
Quoted 3 lines · Andy Shevchenko
strlcpy()andstrlcat()are confusing APIs and the former one already gone from the kernel. In preparation to killstrlcat()replace it with the better alternative.Quoted 8 lines
Quoted 4 lines
Yes please. There are a few places I looked at in the past that might benefit from being changed to
seq_bufor similar (where snprintf doesn't cut it), but otherwise the removal of strlcat should be straight forward and would be well appreciated. :)Thank you for confirming, this is basically the message to Josh to find users and start converting them and kill
strlcat()eventually. Josh, as you see it will be well appreciated!As an example of a
seq_bufuser, seeblock/partitions/core.c:static struct
parsed_partitions*check_partition(struct gendisk *hd){ ... state->pp_buf = (char *)__get_free_page(GFP_KERNEL); ... state->pp_buf[0] = '\0'; ... snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name); ... while (!res && check_part[i]) { ... res = check_part[i++](state);
Quoted 6 lines
...
All the partition handlers then use strlcat to append more details, and it's totally unbounded. The correct thing would be to build a
seq_bufto attach to state instead of thepp_buf, and the handlers would useseq_buffunctions to append their info, etc etc.
Indeed. Thanks for sharing the ideas!
Signature · 2 lines
With Best Regards, Andy Shevchenko