All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Cc: davem@davemloft.net, gregkh@linuxfoundation.org,
	Dave Ertman <david.m.ertman@intel.com>,
	netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	nhorman@redhat.com, sassmann@redhat.com, parav@mellanox.com,
	Kiran Patil <kiran.patil@intel.com>
Subject: Re: [PATCH v3 01/20] virtual-bus: Implementation of Virtual Bus
Date: Tue, 10 Dec 2019 14:22:11 -0400	[thread overview]
Message-ID: <20191210182211.GD46@ziepe.ca> (raw)
In-Reply-To: <20191209224935.1780117-2-jeffrey.t.kirsher@intel.com>

On Mon, Dec 09, 2019 at 02:49:16PM -0800, Jeff Kirsher wrote:

> +#define to_virtbus_dev(x)	(container_of((x), struct virtbus_device, dev))
> +#define to_virtbus_drv(x)	(container_of((x), struct virtbus_driver, \
> +				 driver))

Please use static inlines for things like this, it makes the type
system clearer

> +/**
> + * virtbus_dev_register - add a virtual bus device
> + * @vdev: virtual bus device to add
> + */
> +int virtbus_dev_register(struct virtbus_device *vdev)
> +{
> +	int ret;
> +
> +	device_initialize(&vdev->dev);

I generally try to discourage the pattern where the device_initialize
is inside a function called register.

The kref inside the struct device should be the only kref for this
memory, and the kref system should be setup close to allocating the
memory. Any non-trivial user tends to require access to the kref
before calling register (which should be done last)

> +	/* All device IDs are automatically allocated */
> +	ret = ida_simple_get(&virtbus_dev_ida, 0, 0, GFP_KERNEL);
> +	if (ret < 0)
> +		return ret;

Should this be a cyclic allocation?

> +
> +	vdev->id = ret;
> +	dev_set_name(&vdev->dev, "%s.%d", vdev->name, vdev->id);

This is also stuff that can be useful to do early as the driver can
then use functions like dev_warn/etc

> +struct virtbus_object {
> +	struct virtbus_device vdev;
> +	char name[];
> +};

This whole virtbus_object makes no sense to me

> +
> +/**
> + * virtbus_dev_release - Destroy a virtbus device
> + * @vdev: virtual device to release
> + *
> + * Note that the vdev->data which is separately allocated needs to be
> + * separately freed on it own.

How will that happen?

> + */
> +static void virtbus_dev_release(struct device *dev)
> +{
> +	struct virtbus_object *vo = container_of(dev, struct virtbus_object,
> +						 vdev.dev);
> +
> +	ida_simple_remove(&virtbus_dev_ida, vo->vdev.id);
> +	kfree(vo);
> +}

Is something wrong with my search? I couldn't find a user for this?

If the virtbus framework wants to provide a release function then it
should also provide the alloc and require that the virtbus_device be
at offset 0 in the caller's struct so that the above kfree can work.
(ie like netdev does with the whole priv thing)

I have no idea what the virtbus_object is supposed to be doing here.

> +struct virtbus_device {
> +	const char *name;
> +	int id;

id is always positive, should be unsigned

Jason

  parent reply	other threads:[~2019-12-10 18:22 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-09 22:49 [net-next v3 00/20][pull request] Intel Wired LAN Driver Updates 2019-12-09 Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 01/20] virtual-bus: Implementation of Virtual Bus Jeff Kirsher
2019-12-10  6:49   ` Leon Romanovsky
2019-12-10 17:51     ` Jason Gunthorpe
2019-12-10 15:20   ` Greg KH
2019-12-10 18:22   ` Jason Gunthorpe [this message]
2019-12-09 22:49 ` [PATCH v3 02/20] ice: Initialize and register a virtual bus to provide RDMA Jeff Kirsher
2019-12-10 15:32   ` Greg KH
2019-12-23 19:06   ` Allan, Bruce W
2019-12-09 22:49 ` [PATCH v3 03/20] ice: Implement peer communications Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 04/20] i40e: Register a virtbus device to provide RDMA Jeff Kirsher
2019-12-10 15:33   ` Greg KH
2019-12-10 15:39   ` Greg KH
2019-12-13 23:08     ` Saleem, Shiraz
2019-12-14  8:37       ` Greg KH
2019-12-18 18:57         ` Saleem, Shiraz
2019-12-18 19:20           ` Jason Gunthorpe
2020-01-02 16:01             ` Saleem, Shiraz
2019-12-19  8:46           ` 'Greg KH'
2019-12-16  3:48     ` Parav Pandit
2019-12-16  7:15       ` Greg KH
2019-12-16  8:36         ` Parav Pandit
2019-12-16  8:58           ` Greg KH
2019-12-16  9:17             ` Parav Pandit
2019-12-09 22:49 ` [PATCH v3 05/20] RDMA/irdma: Add driver framework definitions Jeff Kirsher
2019-12-10 19:04   ` Jason Gunthorpe
2019-12-11  6:07     ` Leon Romanovsky
2019-12-12  1:40     ` Saleem, Shiraz
2019-12-12  8:39       ` Leon Romanovsky
2019-12-12  9:12         ` gregkh
2019-12-17 21:00       ` Jason Gunthorpe
2019-12-21  0:00   ` Keller, Jacob E
2019-12-09 22:49 ` [PATCH v3 06/20] RDMA/irdma: Implement device initialization definitions Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 07/20] RDMA/irdma: Implement HW Admin Queue OPs Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 08/20] RDMA/irdma: Add HMC backing store setup functions Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 09/20] RDMA/irdma: Add privileged UDA queue implementation Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 10/20] RDMA/irdma: Add QoS definitions Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 11/20] RDMA/irdma: Add connection manager Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 12/20] RDMA/irdma: Add PBLE resource manager Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 13/20] RDMA/irdma: Implement device supported verb APIs Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 14/20] RDMA/irdma: Add RoCEv2 UD OP support Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 15/20] RDMA/irdma: Add user/kernel shared libraries Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 16/20] RDMA/irdma: Add miscellaneous utility definitions Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 17/20] RDMA/irdma: Add dynamic tracing for CM Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 18/20] RDMA/irdma: Add ABI definitions Jeff Kirsher
2019-12-09 22:49 ` [PATCH v3 19/20] RDMA: Add irdma Kconfig/Makefile and remove i40iw Jeff Kirsher
2019-12-11 20:02   ` Jason Gunthorpe
2019-12-13 23:06     ` Saleem, Shiraz
2019-12-17 21:04       ` Jason Gunthorpe
2020-01-02 16:00         ` Saleem, Shiraz
2020-01-02 17:04           ` Jason Gunthorpe
2020-01-02 17:50             ` Saleem, Shiraz
2020-01-02 18:06               ` Jason Gunthorpe
2019-12-09 22:49 ` [PATCH v3 20/20] RDMA/irdma: Update MAINTAINERS file Jeff Kirsher
2019-12-10  7:33 ` [net-next v3 00/20][pull request] Intel Wired LAN Driver Updates 2019-12-09 Greg KH
2019-12-10 17:22 ` Jason Gunthorpe
2019-12-10 18:06   ` Jeff Kirsher
2019-12-10 18:25     ` Jason Gunthorpe
2019-12-10 18:41       ` Jeff Kirsher
2019-12-10 19:11         ` Jason Gunthorpe
2019-12-10 19:23           ` Jeff Kirsher
2019-12-10 19:44             ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191210182211.GD46@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=davem@davemloft.net \
    --cc=david.m.ertman@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=kiran.patil@intel.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@redhat.com \
    --cc=parav@mellanox.com \
    --cc=sassmann@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.