Commit b98fe24c authored by Himangi Saraogi's avatar Himangi Saraogi Committed by David S. Miller

batman-adv: Use kasprintf

kasprintf 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);
// </smpl>
Signed-off-by: default avatarHimangi Saraogi <himangi774@gmail.com>
Acked-by: default avatarJulia Lawall <julia.lawall@lip6.fr>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0a7fdbde
...@@ -900,32 +900,24 @@ int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type, ...@@ -900,32 +900,24 @@ int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type,
bat_kobj = &bat_priv->soft_iface->dev.kobj; bat_kobj = &bat_priv->soft_iface->dev.kobj;
uevent_env[0] = kmalloc(strlen(BATADV_UEV_TYPE_VAR) + uevent_env[0] = kasprintf(GFP_ATOMIC,
strlen(batadv_uev_type_str[type]) + 1, "%s%s", BATADV_UEV_TYPE_VAR,
GFP_ATOMIC); batadv_uev_type_str[type]);
if (!uevent_env[0]) if (!uevent_env[0])
goto out; goto out;
sprintf(uevent_env[0], "%s%s", BATADV_UEV_TYPE_VAR, uevent_env[1] = kasprintf(GFP_ATOMIC,
batadv_uev_type_str[type]); "%s%s", BATADV_UEV_ACTION_VAR,
batadv_uev_action_str[action]);
uevent_env[1] = kmalloc(strlen(BATADV_UEV_ACTION_VAR) +
strlen(batadv_uev_action_str[action]) + 1,
GFP_ATOMIC);
if (!uevent_env[1]) if (!uevent_env[1])
goto out; goto out;
sprintf(uevent_env[1], "%s%s", BATADV_UEV_ACTION_VAR,
batadv_uev_action_str[action]);
/* If the event is DEL, ignore the data field */ /* If the event is DEL, ignore the data field */
if (action != BATADV_UEV_DEL) { if (action != BATADV_UEV_DEL) {
uevent_env[2] = kmalloc(strlen(BATADV_UEV_DATA_VAR) + uevent_env[2] = kasprintf(GFP_ATOMIC,
strlen(data) + 1, GFP_ATOMIC); "%s%s", BATADV_UEV_DATA_VAR, data);
if (!uevent_env[2]) if (!uevent_env[2])
goto out; goto out;
sprintf(uevent_env[2], "%s%s", BATADV_UEV_DATA_VAR, data);
} }
ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env); ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment