lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160223211948.GT38500@redhat.com>
Date:	Tue, 23 Feb 2016 16:19:48 -0500
From:	Jarod Wilson <jarod@...hat.com>
To:	Jiri Pirko <jiri@...nulli.us>
Cc:	netdev@...r.kernel.org, davem@...emloft.net, idosch@...lanox.com,
	eladr@...lanox.com, yotamg@...lanox.com, ogerlitz@...lanox.com,
	yishaih@...lanox.com, dledford@...hat.com, sean.hefty@...el.com,
	hal.rosenstock@...il.com, eugenia@...lanox.com,
	roopa@...ulusnetworks.com, nikolay@...ulusnetworks.com,
	hadarh@...lanox.com, jhs@...atatu.com, john.fastabend@...il.com,
	jeffrey.t.kirsher@...el.com, brouer@...hat.com, ivecera@...hat.com,
	rami.rosen@...el.com, hannes@...essinduktion.org,
	gospo@...ulusnetworks.com
Subject: Re: [patch net-next v2 1/9] Introduce devlink infrastructure

On Tue, Feb 23, 2016 at 04:51:26PM +0100, Jiri Pirko wrote:
> From: Jiri Pirko <jiri@...lanox.com>
> 
> Introduce devlink infrastructure for drivers to register and expose to
> userspace via generic Netlink interface.
> 
> There are two basic objects defined:
> devlink - one instance for every "parent device", for example switch ASIC
> devlink port - one instance for every physical port of the device.
> 
> This initial portion implements basic get/dump of objects to userspace.
> Also, port splitter and port type setting is implemented.
...
> +/**
> + *	devlink_alloc - Allocate new devlink instance resources
> + *
> + *	@ops: ops
> + *	@priv_size: size of user private data
> + *
> + *	Allocate new devlink instance resources, including devlink index
> + *	and name.
> + */
> +struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size)
> +{
> +	static atomic_t dev_counter = ATOMIC_INIT(0);
> +	struct devlink *devlink;
> +
> +	devlink = kzalloc(sizeof(*devlink) + priv_size, GFP_KERNEL);
> +	if (!devlink)
> +		return NULL;
> +	devlink->ops = ops;
> +	devlink_net_set(devlink, &init_net);
> +
> +different_name:
> +	devlink->index = atomic_inc_return(&dev_counter);
> +	if (devlink->index < 0) {
> +		/* wrapped */
> +		atomic_dec(&dev_counter);
> +		kfree(devlink);
> +		return NULL;
> +	}
> +	/* atomic_inc_return makes it start at 1, make it start at 0 */
> +	devlink->index--;
> +
> +	dev_set_name(&devlink->dev, DEVLINK_GENL_NAME "%d", devlink->index);
> +	if (devlink_name_exists(devlink_net(devlink), devlink_name(devlink)))
> +		goto different_name;
> +
> +	INIT_LIST_HEAD(&devlink->port_list);
> +	device_initialize(&devlink->dev);
> +	devlink->dev.class = &devlink_class;
> +	devlink->dev.platform_data = devlink;
> +	return devlink;
> +}
> +EXPORT_SYMBOL_GPL(devlink_alloc);

The increment then decrement bit feels... Clunky and a little confusing.
Why not just atomic_read(&dev_counter) before different_name:, then an
atomic_inc_return(&dev_counter) under the if clause before the goto, and
eliminate the devlink->index-- bit?

-- 
Jarod Wilson
jarod@...hat.com

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ