* [PATCH v2] staging: lustre: Use kasprintf.
@ 2015-03-01 7:38 Navya Sri Nizamkari
2015-03-01 12:50 ` [Outreachy kernel] " Julia Lawall
0 siblings, 1 reply; 3+ messages in thread
From: Navya Sri Nizamkari @ 2015-03-01 7:38 UTC (permalink / raw)
To: outreachy-kernel
This patch uses kasprintf as it combines kmalloc and
sprintf, and takes care of the size calculation itself.
The semantic patch that makes this change is as follows:
// <smpl>
@@
expression a,flag;
expression list args;
statement S;
@@
a =
- \(kmalloc\|kzalloc\)(...,flag)
+ kasprintf(flag,args)
<... when != a
if (a == NULL || ...) S
...>
- sprintf(a,args);
Signed-off-by: Navya Sri Nizamkari <navyasri.tech@gmail.com>
---
Changes in v2:
-Change arguments of kasprintf to the right ones.
drivers/staging/lustre/lustre/llite/llite_lib.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c
index 0c1b583..26e8626 100644
--- a/drivers/staging/lustre/lustre/llite/llite_lib.c
+++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
@@ -978,19 +978,17 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
lprof->lp_md, lprof->lp_dt);
- dt = kzalloc(strlen(lprof->lp_dt) + instlen + 2, GFP_NOFS);
+ dt = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
if (!dt) {
err = -ENOMEM;
goto out_free;
}
- sprintf(dt, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
- md = kzalloc(strlen(lprof->lp_md) + instlen + 2, GFP_NOFS);
+ md = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
if (!md) {
err = -ENOMEM;
goto out_free;
}
- sprintf(md, "%s-%p", lprof->lp_md, cfg->cfg_instance);
/* connections, registrations, sb setup */
err = client_common_fill_super(sb, md, dt, mnt);
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Outreachy kernel] [PATCH v2] staging: lustre: Use kasprintf.
2015-03-01 7:38 [PATCH v2] staging: lustre: Use kasprintf Navya Sri Nizamkari
@ 2015-03-01 12:50 ` Julia Lawall
2015-03-01 16:17 ` Navya Sri Nizamkari
0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2015-03-01 12:50 UTC (permalink / raw)
To: Navya Sri Nizamkari; +Cc: outreachy-kernel
On Sun, 1 Mar 2015, Navya Sri Nizamkari wrote:
> This patch uses kasprintf as it combines kmalloc and
> sprintf, and takes care of the size calculation itself.
>
> The semantic patch that makes this change is as follows:
>
> // <smpl>
> @@
> expression a,flag;
> expression list args;
> statement S;
> @@
>
> a =
> - \(kmalloc\|kzalloc\)(...,flag)
> + kasprintf(flag,args)
> <... when != a
> if (a == NULL || ...) S
> ...>
> - sprintf(a,args);
Nice :)
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
>
> Signed-off-by: Navya Sri Nizamkari <navyasri.tech@gmail.com>
> ---
> Changes in v2:
> -Change arguments of kasprintf to the right ones.
>
> drivers/staging/lustre/lustre/llite/llite_lib.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c
> index 0c1b583..26e8626 100644
> --- a/drivers/staging/lustre/lustre/llite/llite_lib.c
> +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
> @@ -978,19 +978,17 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
> CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
> lprof->lp_md, lprof->lp_dt);
>
> - dt = kzalloc(strlen(lprof->lp_dt) + instlen + 2, GFP_NOFS);
> + dt = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
> if (!dt) {
> err = -ENOMEM;
> goto out_free;
> }
> - sprintf(dt, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
>
> - md = kzalloc(strlen(lprof->lp_md) + instlen + 2, GFP_NOFS);
> + md = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
> if (!md) {
> err = -ENOMEM;
> goto out_free;
> }
> - sprintf(md, "%s-%p", lprof->lp_md, cfg->cfg_instance);
>
> /* connections, registrations, sb setup */
> err = client_common_fill_super(sb, md, dt, mnt);
> --
> 1.9.1
>
> --
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20150301073759.GA21185%40localhost.
> For more options, visit https://groups.google.com/d/optout.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Outreachy kernel] [PATCH v2] staging: lustre: Use kasprintf.
2015-03-01 12:50 ` [Outreachy kernel] " Julia Lawall
@ 2015-03-01 16:17 ` Navya Sri Nizamkari
0 siblings, 0 replies; 3+ messages in thread
From: Navya Sri Nizamkari @ 2015-03-01 16:17 UTC (permalink / raw)
To: outreachy-kernel; +Cc: navyasri.tech
[-- Attachment #1.1: Type: text/plain, Size: 2882 bytes --]
On Sunday, March 1, 2015 at 6:20:16 PM UTC+5:30, Julia Lawall wrote:
>
> On Sun, 1 Mar 2015, Navya Sri Nizamkari wrote:
>
> > This patch uses kasprintf as it combines kmalloc and
> > sprintf, and takes care of the size calculation itself.
> >
> > The semantic patch that makes this change is as follows:
> >
> > // <smpl>
> > @@
> > expression a,flag;
> > expression list args;
> > statement S;
> > @@
> >
> > a =
> > - \(kmalloc\|kzalloc\)(...,flag)
> > + kasprintf(flag,args)
> > <... when != a
> > if (a == NULL || ...) S
> > ...>
> > - sprintf(a,args);
>
> Nice :)
>
> Acked-by: Julia Lawall <julia....@lip6.fr <javascript:>>
>
> Thank You :)
> >
> > Signed-off-by: Navya Sri Nizamkari <navyas...@gmail.com <javascript:>>
> > ---
> > Changes in v2:
> > -Change arguments of kasprintf to the right ones.
> >
> > drivers/staging/lustre/lustre/llite/llite_lib.c | 6 ++----
> > 1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c
> b/drivers/staging/lustre/lustre/llite/llite_lib.c
> > index 0c1b583..26e8626 100644
> > --- a/drivers/staging/lustre/lustre/llite/llite_lib.c
> > +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
> > @@ -978,19 +978,17 @@ int ll_fill_super(struct super_block *sb, struct
> vfsmount *mnt)
> > CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n",
> profilenm,
> > lprof->lp_md, lprof->lp_dt);
> >
> > - dt = kzalloc(strlen(lprof->lp_dt) + instlen + 2, GFP_NOFS);
> > + dt = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt,
> cfg->cfg_instance);
> > if (!dt) {
> > err = -ENOMEM;
> > goto out_free;
> > }
> > - sprintf(dt, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
> >
> > - md = kzalloc(strlen(lprof->lp_md) + instlen + 2, GFP_NOFS);
> > + md = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt,
> cfg->cfg_instance);
> > if (!md) {
> > err = -ENOMEM;
> > goto out_free;
> > }
> > - sprintf(md, "%s-%p", lprof->lp_md, cfg->cfg_instance);
> >
> > /* connections, registrations, sb setup */
> > err = client_common_fill_super(sb, md, dt, mnt);
> > --
> > 1.9.1
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "outreachy-kernel" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to outreachy-kern...@googlegroups.com <javascript:>.
> > To post to this group, send email to outreach...@googlegroups.com
> <javascript:>.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/outreachy-kernel/20150301073759.GA21185%40localhost.
>
> > For more options, visit https://groups.google.com/d/optout.
> >
>
[-- Attachment #1.2: Type: text/html, Size: 5080 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-01 16:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-01 7:38 [PATCH v2] staging: lustre: Use kasprintf Navya Sri Nizamkari
2015-03-01 12:50 ` [Outreachy kernel] " Julia Lawall
2015-03-01 16:17 ` Navya Sri Nizamkari
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.