All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ACPI: move from strlcpy with unused retval to strscpy
@ 2022-08-18 20:59 Wolfram Sang
  2022-08-23 16:58 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Wolfram Sang @ 2022-08-18 20:59 UTC (permalink / raw)
  To: linux-kernel; +Cc: Wolfram Sang, Rafael J. Wysocki, Len Brown, linux-acpi

Follow the advice of the below link and prefer 'strscpy' in this
subsystem. Conversion is 1:1 because the return value is not used.
Generated by a coccinelle script.

Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/acpi/bus.c            | 4 ++--
 drivers/acpi/processor_idle.c | 8 ++++----
 drivers/acpi/utils.c          | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index c0d20d997891..1d29f5dc7d79 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -802,7 +802,7 @@ static bool acpi_of_modalias(struct acpi_device *adev,
 
 	str = obj->string.pointer;
 	chr = strchr(str, ',');
-	strlcpy(modalias, chr ? chr + 1 : str, len);
+	strscpy(modalias, chr ? chr + 1 : str, len);
 
 	return true;
 }
@@ -822,7 +822,7 @@ void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
 		       char *modalias, size_t len)
 {
 	if (!acpi_of_modalias(adev, modalias, len))
-		strlcpy(modalias, default_id, len);
+		strscpy(modalias, default_id, len);
 }
 EXPORT_SYMBOL_GPL(acpi_set_modalias);
 
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 16a1663d02d4..1778016ea895 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -787,7 +787,7 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr)
 
 		state = &drv->states[count];
 		snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
-		strlcpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
+		strscpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
 		state->exit_latency = cx->latency;
 		state->target_residency = cx->latency * latency_factor;
 		state->enter = acpi_idle_enter;
@@ -956,7 +956,7 @@ static int acpi_processor_evaluate_lpi(acpi_handle handle,
 
 		obj = pkg_elem + 9;
 		if (obj->type == ACPI_TYPE_STRING)
-			strlcpy(lpi_state->desc, obj->string.pointer,
+			strscpy(lpi_state->desc, obj->string.pointer,
 				ACPI_CX_DESC_LEN);
 
 		lpi_state->index = state_idx;
@@ -1022,7 +1022,7 @@ static bool combine_lpi_states(struct acpi_lpi_state *local,
 	result->arch_flags = parent->arch_flags;
 	result->index = parent->index;
 
-	strlcpy(result->desc, local->desc, ACPI_CX_DESC_LEN);
+	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);
 	return true;
@@ -1196,7 +1196,7 @@ static int acpi_processor_setup_lpi_states(struct acpi_processor *pr)
 
 		state = &drv->states[i];
 		snprintf(state->name, CPUIDLE_NAME_LEN, "LPI-%d", i);
-		strlcpy(state->desc, lpi->desc, CPUIDLE_DESC_LEN);
+		strscpy(state->desc, lpi->desc, CPUIDLE_DESC_LEN);
 		state->exit_latency = lpi->wake_latency;
 		state->target_residency = lpi->min_residency;
 		if (lpi->arch_flags)
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 5a7b8065e77f..4acd6f7d1395 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -878,7 +878,7 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
 	struct acpi_dev_match_info match = {};
 	struct device *dev;
 
-	strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
+	strscpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
 	match.uid = uid;
 	match.hrv = hrv;
 
@@ -911,7 +911,7 @@ acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const cha
 	struct acpi_dev_match_info match = {};
 	struct device *dev;
 
-	strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
+	strscpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
 	match.uid = uid;
 	match.hrv = hrv;
 
@@ -961,7 +961,7 @@ EXPORT_SYMBOL(acpi_video_backlight_string);
 
 static int __init acpi_backlight(char *str)
 {
-	strlcpy(acpi_video_backlight_string, str,
+	strscpy(acpi_video_backlight_string, str,
 		sizeof(acpi_video_backlight_string));
 	return 1;
 }
-- 
2.35.1


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

* Re: [PATCH] ACPI: move from strlcpy with unused retval to strscpy
  2022-08-18 20:59 [PATCH] ACPI: move from strlcpy with unused retval to strscpy Wolfram Sang
@ 2022-08-23 16:58 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2022-08-23 16:58 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Linux Kernel Mailing List, Rafael J. Wysocki, Len Brown,
	ACPI Devel Maling List

On Thu, Aug 18, 2022 at 11:00 PM Wolfram Sang
<wsa+renesas@sang-engineering.com> wrote:
>
> Follow the advice of the below link and prefer 'strscpy' in this
> subsystem. Conversion is 1:1 because the return value is not used.
> Generated by a coccinelle script.
>
> Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  drivers/acpi/bus.c            | 4 ++--
>  drivers/acpi/processor_idle.c | 8 ++++----
>  drivers/acpi/utils.c          | 6 +++---
>  3 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
> index c0d20d997891..1d29f5dc7d79 100644
> --- a/drivers/acpi/bus.c
> +++ b/drivers/acpi/bus.c
> @@ -802,7 +802,7 @@ static bool acpi_of_modalias(struct acpi_device *adev,
>
>         str = obj->string.pointer;
>         chr = strchr(str, ',');
> -       strlcpy(modalias, chr ? chr + 1 : str, len);
> +       strscpy(modalias, chr ? chr + 1 : str, len);
>
>         return true;
>  }
> @@ -822,7 +822,7 @@ void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
>                        char *modalias, size_t len)
>  {
>         if (!acpi_of_modalias(adev, modalias, len))
> -               strlcpy(modalias, default_id, len);
> +               strscpy(modalias, default_id, len);
>  }
>  EXPORT_SYMBOL_GPL(acpi_set_modalias);
>
> diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
> index 16a1663d02d4..1778016ea895 100644
> --- a/drivers/acpi/processor_idle.c
> +++ b/drivers/acpi/processor_idle.c
> @@ -787,7 +787,7 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr)
>
>                 state = &drv->states[count];
>                 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
> -               strlcpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
> +               strscpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
>                 state->exit_latency = cx->latency;
>                 state->target_residency = cx->latency * latency_factor;
>                 state->enter = acpi_idle_enter;
> @@ -956,7 +956,7 @@ static int acpi_processor_evaluate_lpi(acpi_handle handle,
>
>                 obj = pkg_elem + 9;
>                 if (obj->type == ACPI_TYPE_STRING)
> -                       strlcpy(lpi_state->desc, obj->string.pointer,
> +                       strscpy(lpi_state->desc, obj->string.pointer,
>                                 ACPI_CX_DESC_LEN);
>
>                 lpi_state->index = state_idx;
> @@ -1022,7 +1022,7 @@ static bool combine_lpi_states(struct acpi_lpi_state *local,
>         result->arch_flags = parent->arch_flags;
>         result->index = parent->index;
>
> -       strlcpy(result->desc, local->desc, ACPI_CX_DESC_LEN);
> +       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);
>         return true;
> @@ -1196,7 +1196,7 @@ static int acpi_processor_setup_lpi_states(struct acpi_processor *pr)
>
>                 state = &drv->states[i];
>                 snprintf(state->name, CPUIDLE_NAME_LEN, "LPI-%d", i);
> -               strlcpy(state->desc, lpi->desc, CPUIDLE_DESC_LEN);
> +               strscpy(state->desc, lpi->desc, CPUIDLE_DESC_LEN);
>                 state->exit_latency = lpi->wake_latency;
>                 state->target_residency = lpi->min_residency;
>                 if (lpi->arch_flags)
> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
> index 5a7b8065e77f..4acd6f7d1395 100644
> --- a/drivers/acpi/utils.c
> +++ b/drivers/acpi/utils.c
> @@ -878,7 +878,7 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
>         struct acpi_dev_match_info match = {};
>         struct device *dev;
>
> -       strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
> +       strscpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
>         match.uid = uid;
>         match.hrv = hrv;
>
> @@ -911,7 +911,7 @@ acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const cha
>         struct acpi_dev_match_info match = {};
>         struct device *dev;
>
> -       strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
> +       strscpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
>         match.uid = uid;
>         match.hrv = hrv;
>
> @@ -961,7 +961,7 @@ EXPORT_SYMBOL(acpi_video_backlight_string);
>
>  static int __init acpi_backlight(char *str)
>  {
> -       strlcpy(acpi_video_backlight_string, str,
> +       strscpy(acpi_video_backlight_string, str,
>                 sizeof(acpi_video_backlight_string));
>         return 1;
>  }
> --

Applied as 6.1 material, thanks!

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

end of thread, other threads:[~2022-08-23 18:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-18 20:59 [PATCH] ACPI: move from strlcpy with unused retval to strscpy Wolfram Sang
2022-08-23 16:58 ` Rafael J. Wysocki

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.