Skip to contentSkip to conversation

PM: hibernate: Remove size arguments when calling strscpy()

PATCH Applied Thorsten Blum 2 participants 2 messages Mar 18, 2025 – Apr 9, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM: hibernate: Remove size arguments when calling strscpy()

The size parameter is optional and strscpy() automatically determines the length of the destination buffer using sizeof() if the argument is omitted. This makes the explicit sizeof() calls unnecessary. Remove them to shorten and simplify the code.

---
 kernel/power/hibernate.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
kernel/power/hibernate.c +4 -5
index 10a01af63a80..ddf7c4a5736f 100644
@@ -756,7 +756,7 @@ int hibernate(void)
 	 * Query for the compression algorithm support if compression is enabled.
 	 */
 	if (!nocompress) {
-		strscpy(hib_comp_algo, hibernate_compressor, sizeof(hib_comp_algo));
+		strscpy(hib_comp_algo, hibernate_compressor);
 		if (crypto_has_comp(hib_comp_algo, 0, 0) != 1) {
 			pr_err("%s compression is not available\n", hib_comp_algo);
 			return -EOPNOTSUPP;
@@ -1005,9 +1005,9 @@ static int software_resume(void)
 	 */
 	if (!(swsusp_header_flags & SF_NOCOMPRESS_MODE)) {
 		if (swsusp_header_flags & SF_COMPRESSION_ALG_LZ4)
-			strscpy(hib_comp_algo, COMPRESSION_ALGO_LZ4, sizeof(hib_comp_algo));
+			strscpy(hib_comp_algo, COMPRESSION_ALGO_LZ4);
 		else
-			strscpy(hib_comp_algo, COMPRESSION_ALGO_LZO, sizeof(hib_comp_algo));
+			strscpy(hib_comp_algo, COMPRESSION_ALGO_LZO);
 		if (crypto_has_comp(hib_comp_algo, 0, 0) != 1) {
 			pr_err("%s compression is not available\n", hib_comp_algo);
 			error = -EOPNOTSUPP;
@@ -1455,8 +1455,7 @@ static int hibernate_compressor_param_set(const char *compressor,
 	if (index >= 0) {
 		ret = param_set_copystring(comp_alg_enabled[index], kp);
 		if (!ret)
-			strscpy(hib_comp_algo, comp_alg_enabled[index],
-				sizeof(hib_comp_algo));
+			strscpy(hib_comp_algo, comp_alg_enabled[index]);
 	} else {
 		ret = index;
 	}
Signature · 1 line
2.48.1
maintainer Applied
#1 lore raw
Quoted 37 lines · Thorsten Blum

The size parameter is optional and strscpy() automatically determines the length of the destination buffer using sizeof() if the argument is omitted. This makes the explicit sizeof() calls unnecessary. Remove them to shorten and simplify the code.

---
 kernel/power/hibernate.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
kernel/power/hibernate.c +3 -3
index 10a01af63a80..ddf7c4a5736f 100644
@@ -756,7 +756,7 @@ int hibernate(void)
         * Query for the compression algorithm support if compression is enabled.
         */
        if (!nocompress) {
-               strscpy(hib_comp_algo, hibernate_compressor, sizeof(hib_comp_algo));
+               strscpy(hib_comp_algo, hibernate_compressor);
                if (crypto_has_comp(hib_comp_algo, 0, 0) != 1) {
                        pr_err("%s compression is not available\n", hib_comp_algo);
                        return -EOPNOTSUPP;
@@ -1005,9 +1005,9 @@ static int software_resume(void)
         */
        if (!(swsusp_header_flags & SF_NOCOMPRESS_MODE)) {
                if (swsusp_header_flags & SF_COMPRESSION_ALG_LZ4)
-                       strscpy(hib_comp_algo, COMPRESSION_ALGO_LZ4, sizeof(hib_comp_algo));
+                       strscpy(hib_comp_algo, COMPRESSION_ALGO_LZ4);
                else
-                       strscpy(hib_comp_algo, COMPRESSION_ALGO_LZO, sizeof(hib_comp_algo));
+                       strscpy(hib_comp_algo, COMPRESSION_ALGO_LZO);
                if (crypto_has_comp(hib_comp_algo, 0, 0) != 1) {
                        pr_err("%s compression is not available\n", hib_comp_algo);
                        error = -EOPNOTSUPP;

kernel/power/hibernate.c static int hibernate_compressor_param_set(const char *compressor,

Quoted 10 lines
kernel/power/hibernate.c +1 -3
@@ -1455,8 +1455,7 @@ static int hibernate_compressor_param_set(const char *compressor,
        if (index >= 0) {
                ret = param_set_copystring(comp_alg_enabled[index], kp);
                if (!ret)
-                       strscpy(hib_comp_algo, comp_alg_enabled[index],
-                               sizeof(hib_comp_algo));
+                       strscpy(hib_comp_algo, comp_alg_enabled[index]);
        } else {
                ret = index;
        }
--

Applied as 6.16 material, thanks!