diff mbox

mISDN: use kstrdup() in dsp_pipeline_build

Message ID 1efbeaf13aca3797e7d7f899ca00b27e37bbde9d.1444498002.git.geliangtang@163.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Geliang Tang Oct. 10, 2015, 9:32 a.m. UTC
Use kstrdup instead of strlen-kmalloc-strcpy.

Signed-off-by: Geliang Tang <geliangtang@163.com>
---
 drivers/isdn/mISDN/dsp_pipeline.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

Comments

Joe Perches Oct. 10, 2015, 7:22 p.m. UTC | #1
On Sat, 2015-10-10 at 02:32 -0700, Geliang Tang wrote:
> Use kstrdup instead of strlen-kmalloc-strcpy.

Not the same code.

Instead of returning early, a 0 length string will
now set pipeline->inuse to 0.

Maybe that's OK, but you should state why in the
commit log.

> diff --git a/drivers/isdn/mISDN/dsp_pipeline.c b/drivers/isdn/mISDN/dsp_pipeline.c
[]
> @@ -250,14 +250,9 @@ int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg)
>  	if (!cfg)
>  		return 0;
>  
> -	len = strlen(cfg);
> -	if (!len)
> -		return 0;
> -
> -	dup = kmalloc(len + 1, GFP_ATOMIC);
> +	dup = kstrdup(cfg, GFP_ATOMIC);
>  	if (!dup)
>  		return 0;
> -	strcpy(dup, cfg);
>  	while ((tok = strsep(&dup, "|"))) {
>  		if (!strlen(tok))
>  			continue;



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/isdn/mISDN/dsp_pipeline.c b/drivers/isdn/mISDN/dsp_pipeline.c
index 8b1a66c..c60722d 100644
--- a/drivers/isdn/mISDN/dsp_pipeline.c
+++ b/drivers/isdn/mISDN/dsp_pipeline.c
@@ -235,7 +235,7 @@  void dsp_pipeline_destroy(struct dsp_pipeline *pipeline)
 
 int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg)
 {
-	int len, incomplete = 0, found = 0;
+	int incomplete = 0, found = 0;
 	char *dup, *tok, *name, *args;
 	struct dsp_element_entry *entry, *n;
 	struct dsp_pipeline_entry *pipeline_entry;
@@ -250,14 +250,9 @@  int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg)
 	if (!cfg)
 		return 0;
 
-	len = strlen(cfg);
-	if (!len)
-		return 0;
-
-	dup = kmalloc(len + 1, GFP_ATOMIC);
+	dup = kstrdup(cfg, GFP_ATOMIC);
 	if (!dup)
 		return 0;
-	strcpy(dup, cfg);
 	while ((tok = strsep(&dup, "|"))) {
 		if (!strlen(tok))
 			continue;