dyndbg: replace kstrdup() + strchr() with kstrdup_and_replace()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 13 Feb 2024 16:27:41 +0000 (18:27 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 6 Mar 2024 21:07:39 +0000 (13:07 -0800)
Replace open coded functionalify of kstrdup_and_replace() with a call.

Link: https://lkml.kernel.org/r/20240213162741.3102810-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Cc: Jason Baron <jbaron@akamai.com>
Cc: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/dynamic_debug.c

index 6fba6423cc10b512acdfac38cc44887a626c8096..c78f335fa98137664745e6593c98b707a528bf34 100644 (file)
@@ -640,10 +640,9 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pa
        int cls_id, totct = 0;
        bool wanted;
 
-       cl_str = tmp = kstrdup(instr, GFP_KERNEL);
-       p = strchr(cl_str, '\n');
-       if (p)
-               *p = '\0';
+       cl_str = tmp = kstrdup_and_replace(instr, '\n', '\0', GFP_KERNEL);
+       if (!tmp)
+               return -ENOMEM;
 
        /* start with previously set state-bits, then modify */
        curr_bits = old_bits = *dcp->bits;