Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 629286b9 authored by Xiaochen Wang's avatar Xiaochen Wang Committed by David Woodhouse
Browse files

mtd: sm_rtl: check kmalloc return value



Because malloc/kzalloc may fail, we should check kmalloc/kzalloc return value
 in sm_create_sysfs_attributes(), mtd/sm_rtl.c and do error handling.
Meanwhile, we should check sm_create_sysfs_attributes return value.

Signed-off-by: default avatarXiaochen Wang <wangxiaochen0@gmail.com>
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 1065cda8
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -64,12 +64,16 @@ struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
					SM_SMALL_PAGE - SM_CIS_VENDOR_OFFSET);
					SM_SMALL_PAGE - SM_CIS_VENDOR_OFFSET);


	char *vendor = kmalloc(vendor_len, GFP_KERNEL);
	char *vendor = kmalloc(vendor_len, GFP_KERNEL);
	if (!vendor)
		goto error1;
	memcpy(vendor, ftl->cis_buffer + SM_CIS_VENDOR_OFFSET, vendor_len);
	memcpy(vendor, ftl->cis_buffer + SM_CIS_VENDOR_OFFSET, vendor_len);
	vendor[vendor_len] = 0;
	vendor[vendor_len] = 0;


	/* Initialize sysfs attributes */
	/* Initialize sysfs attributes */
	vendor_attribute =
	vendor_attribute =
		kzalloc(sizeof(struct sm_sysfs_attribute), GFP_KERNEL);
		kzalloc(sizeof(struct sm_sysfs_attribute), GFP_KERNEL);
	if (!vendor_attribute)
		goto error2;


	sysfs_attr_init(&vendor_attribute->dev_attr.attr);
	sysfs_attr_init(&vendor_attribute->dev_attr.attr);


@@ -83,12 +87,24 @@ struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
	/* Create array of pointers to the attributes */
	/* Create array of pointers to the attributes */
	attributes = kzalloc(sizeof(struct attribute *) * (NUM_ATTRIBUTES + 1),
	attributes = kzalloc(sizeof(struct attribute *) * (NUM_ATTRIBUTES + 1),
								GFP_KERNEL);
								GFP_KERNEL);
	if (!attributes)
		goto error3;
	attributes[0] = &vendor_attribute->dev_attr.attr;
	attributes[0] = &vendor_attribute->dev_attr.attr;


	/* Finally create the attribute group */
	/* Finally create the attribute group */
	attr_group = kzalloc(sizeof(struct attribute_group), GFP_KERNEL);
	attr_group = kzalloc(sizeof(struct attribute_group), GFP_KERNEL);
	if (!attr_group)
		goto error4;
	attr_group->attrs = attributes;
	attr_group->attrs = attributes;
	return attr_group;
	return attr_group;
error4:
	kfree(attributes);
error3:
	kfree(vendor_attribute);
error2:
	kfree(vendor);
error1:
	return NULL;
}
}


void sm_delete_sysfs_attributes(struct sm_ftl *ftl)
void sm_delete_sysfs_attributes(struct sm_ftl *ftl)
@@ -1178,6 +1194,8 @@ static void sm_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
	}
	}


	ftl->disk_attributes = sm_create_sysfs_attributes(ftl);
	ftl->disk_attributes = sm_create_sysfs_attributes(ftl);
	if (!ftl->disk_attributes)
		goto error6;
	trans->disk_attributes = ftl->disk_attributes;
	trans->disk_attributes = ftl->disk_attributes;


	sm_printk("Found %d MiB xD/SmartMedia FTL on mtd%d",
	sm_printk("Found %d MiB xD/SmartMedia FTL on mtd%d",