Re: [RFC] Generic VME UIO

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 22, 2015 at 09:09:06PM +0300, Dmitry Kalinkin wrote:
> +	for (level = 1; level <= 7; level++) {
> +		char *level_node_name = kasprintf(GFP_KERNEL, "%d", level);
> +		struct kobject *level_node = kobject_create_and_add(
> +			level_node_name, kobj);
> +		if (!level_node)
> +			return -ENOMEM;

>From the zero day testing results, what I've noticed is that allocations
in the initializer are more error prone.  You should be testing the
results from kasprintf() and there is a leak if the "level_node"
allocation fails.

		char *level_node_name;
		struct kobject *level_node;

		level_node_name = kasprintf(GFP_KERNEL, "%d", level);
		if (!level_node_name)
			return -ENOMEM;
		level_node = kobject_create_and_add(level_node_name, kobj);
		if (!level_node) {
			kfree(level_node_name);
			return -ENOMEM;
		}

The other advantage to writing it like this is that you don't run into
the 80 char limit.

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux