Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1190682

Re: [RFC] Generic VME UIO

From Dan Carpenter <dan.carpenter@oracle.com>
Newsgroups linux.kernel
Subject Re: [RFC] Generic VME UIO
Date 2015-07-23 09:30 +0200
Message-ID <pPj75-8jO-35@gated-at.bofh.it> (permalink)
References <pP6CR-7ac-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[RFC] Generic VME UIO Dmitry Kalinkin <dmitry.kalinkin@gmail.com> - 2015-07-22 20:10 +0200
  Re: [RFC] Generic VME UIO Dan Carpenter <dan.carpenter@oracle.com> - 2015-07-23 09:30 +0200

csiph-web