提交 56116b2b 编写于 作者: I Iulia Manda 提交者: Peter P Waskiewicz Jr

staging: unisys: visorutil: Use kzalloc instead of kmalloc with memset

Fix coccinelle warnings of better allocation by using kzalloc.
In these cases, kzalloc is preferred, as kmalloc may fail if it does not find
contiguous memory.
Signed-off-by: NIulia Manda <iulia.manda21@gmail.com>
Acked-by: NLuis R. Rodriguez <mcgrof@do-not-panic.com>
Signed-off-by: NPeter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
上级 464a5028
...@@ -140,10 +140,9 @@ MYPROCTYPE *visor_proc_CreateType(struct proc_dir_entry *procDirRoot, ...@@ -140,10 +140,9 @@ MYPROCTYPE *visor_proc_CreateType(struct proc_dir_entry *procDirRoot,
FAIL("procDirRoot cannot be NULL!", 0); FAIL("procDirRoot cannot be NULL!", 0);
if (name == NULL || name[0] == NULL) if (name == NULL || name[0] == NULL)
FAIL("name must contain at least 1 node name!", 0); FAIL("name must contain at least 1 node name!", 0);
type = kmalloc(sizeof(MYPROCTYPE), GFP_KERNEL|__GFP_NORETRY); type = kzalloc(sizeof(MYPROCTYPE), GFP_KERNEL | __GFP_NORETRY);
if (type == NULL) if (type == NULL)
FAIL("out of memory", 0); FAIL("out of memory", 0);
memset(type, 0, sizeof(MYPROCTYPE));
type->name = name; type->name = name;
type->propertyNames = propertyNames; type->propertyNames = propertyNames;
type->nProperties = 0; type->nProperties = 0;
...@@ -155,13 +154,11 @@ MYPROCTYPE *visor_proc_CreateType(struct proc_dir_entry *procDirRoot, ...@@ -155,13 +154,11 @@ MYPROCTYPE *visor_proc_CreateType(struct proc_dir_entry *procDirRoot,
type->nProperties++; type->nProperties++;
while (type->name[type->nNames] != NULL) while (type->name[type->nNames] != NULL)
type->nNames++; type->nNames++;
type->procDirs = kmalloc((type->nNames+1)* type->procDirs = kzalloc((type->nNames + 1) *
sizeof(struct proc_dir_entry *), sizeof(struct proc_dir_entry *),
GFP_KERNEL|__GFP_NORETRY); GFP_KERNEL | __GFP_NORETRY);
if (type->procDirs == NULL) if (type->procDirs == NULL)
FAIL("out of memory", 0); FAIL("out of memory", 0);
memset(type->procDirs, 0, (type->nNames + 1) *
sizeof(struct proc_dir_entry *));
parent = procDirRoot; parent = procDirRoot;
for (i = 0; i < type->nNames; i++) { for (i = 0; i < type->nNames; i++) {
type->procDirs[i] = createProcDir(type->name[i], parent); type->procDirs[i] = createProcDir(type->name[i], parent);
...@@ -218,10 +215,9 @@ MYPROCOBJECT *visor_proc_CreateObject(MYPROCTYPE *type, ...@@ -218,10 +215,9 @@ MYPROCOBJECT *visor_proc_CreateObject(MYPROCTYPE *type,
if (type == NULL) if (type == NULL)
FAIL("type cannot be NULL", 0); FAIL("type cannot be NULL", 0);
obj = kmalloc(sizeof(MYPROCOBJECT), GFP_KERNEL | __GFP_NORETRY); obj = kzalloc(sizeof(MYPROCOBJECT), GFP_KERNEL | __GFP_NORETRY);
if (obj == NULL) if (obj == NULL)
FAIL("out of memory", 0); FAIL("out of memory", 0);
memset(obj, 0, sizeof(MYPROCOBJECT));
obj->type = type; obj->type = type;
obj->context = context; obj->context = context;
if (name == NULL) { if (name == NULL) {
...@@ -240,19 +236,15 @@ MYPROCOBJECT *visor_proc_CreateObject(MYPROCTYPE *type, ...@@ -240,19 +236,15 @@ MYPROCOBJECT *visor_proc_CreateObject(MYPROCTYPE *type,
RETPTR(NULL); RETPTR(NULL);
} }
obj->procDirPropertyContexts = obj->procDirPropertyContexts =
kmalloc((type->nProperties+1)*sizeof(PROCDIRENTRYCONTEXT), kzalloc((type->nProperties + 1) * sizeof(PROCDIRENTRYCONTEXT),
GFP_KERNEL|__GFP_NORETRY); GFP_KERNEL | __GFP_NORETRY);
if (obj->procDirPropertyContexts == NULL) if (obj->procDirPropertyContexts == NULL)
FAIL("out of memory", 0); FAIL("out of memory", 0);
memset(obj->procDirPropertyContexts, 0,
(type->nProperties+1)*sizeof(PROCDIRENTRYCONTEXT));
obj->procDirProperties = obj->procDirProperties =
kmalloc((type->nProperties+1) * sizeof(struct proc_dir_entry *), kzalloc((type->nProperties + 1) * sizeof(struct proc_dir_entry *),
GFP_KERNEL|__GFP_NORETRY); GFP_KERNEL | __GFP_NORETRY);
if (obj->procDirProperties == NULL) if (obj->procDirProperties == NULL)
FAIL("out of memory", 0); FAIL("out of memory", 0);
memset(obj->procDirProperties, 0,
(type->nProperties+1) * sizeof(struct proc_dir_entry *));
for (i = 0; i < type->nProperties; i++) { for (i = 0; i < type->nProperties; i++) {
obj->procDirPropertyContexts[i].procObject = obj; obj->procDirPropertyContexts[i].procObject = obj;
obj->procDirPropertyContexts[i].propertyIndex = i; obj->procDirPropertyContexts[i].propertyIndex = i;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册