linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Jason Wang" <jasowang@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Jean-Philippe Brucker" <jean-philippe@linaro.org>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Bill Mills" <bill.mills@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Enrico Weigelt, metux IT consult" <info@metux.net>,
	"Jie Deng" <jie.deng@intel.com>,
	DTML <devicetree@vger.kernel.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"open list:DRM DRIVER FOR QEMU'S CIRRUS DEVICE"
	<virtualization@lists.linux-foundation.org>
Subject: Re: [PATCH V2 5/5] virtio: Bind virtio device to device-tree node
Date: Thu, 22 Jul 2021 16:52:07 +0200	[thread overview]
Message-ID: <CAK8P3a0iQ5dt_38Y9j6XCoj=n7YA+cPz7i6mjP24k9WY7QL+oA@mail.gmail.com> (raw)
In-Reply-To: <026ad5f274d64d46590623f9f3a04b8abfbe62d7.1626947324.git.viresh.kumar@linaro.org>

On Thu, Jul 22, 2021 at 11:56 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> +/* Virtio device compatibles and IDs */
> +static const struct of_device_id of_virtio_devices[] = {
> +       { .compatible = "virtio,22", .data = (void *)VIRTIO_ID_I2C_ADAPTER },
> +       { .compatible = "virtio,29", .data = (void *)VIRTIO_ID_GPIO },
> +       { }
> +};
> +
> +static int virtio_device_of_init(struct virtio_device *dev)
> +{
> +       struct device_node *np, *pnode = dev->dev.parent->of_node;
> +       const struct of_device_id *match;
> +       int ret, count;
> +
> +       if (!pnode)
> +               return 0;
> +
> +       count = of_get_available_child_count(pnode);
> +       if (!count)
> +               return 0;
> +
> +       /* There can be only 1 child node */
> +       if (WARN_ON(count > 1))
> +               return -EINVAL;
> +
> +       np = of_get_next_available_child(pnode, NULL);
> +       if (WARN_ON(!np))
> +               return -ENODEV;
> +
> +       match = of_match_node(of_virtio_devices, np);
> +       if (!match) {
> +               ret = -ENODEV;
> +               goto out;
> +       }

I think it would be better not to have to enumerate the of_virtio_devices[]
strings, but instead use of_device_is_compatible() to match against
"virtio,%d". Otherwise we end up modifying this function for every
virtio driver that needs a binding.

       Arnd

  reply	other threads:[~2021-07-22 14:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22  9:56 [PATCH V2 0/5] virtio: Add virtio-device bindings Viresh Kumar
2021-07-22  9:56 ` [PATCH V2 1/5] dt-bindings: virtio: Add binding for virtio devices Viresh Kumar
2021-07-22 10:28   ` Arnd Bergmann
2021-07-22 10:32     ` Viresh Kumar
2021-07-22  9:56 ` [PATCH V2 2/5] dt-bindings: i2c: Add bindings for i2c-virtio Viresh Kumar
2021-07-22 14:45   ` Wolfram Sang
2021-07-22  9:56 ` [PATCH V2 3/5] dt-bindings: gpio: Add bindings for gpio-virtio Viresh Kumar
2021-07-22  9:56 ` [PATCH V2 4/5] uapi: virtio_ids: Sync ids with specification Viresh Kumar
2021-07-22  9:56 ` [PATCH V2 5/5] virtio: Bind virtio device to device-tree node Viresh Kumar
2021-07-22 14:52   ` Arnd Bergmann [this message]
2021-07-23  1:30     ` Viresh Kumar
2021-07-23  6:11   ` [PATCH V2.1 " Viresh Kumar
2021-07-23  8:59     ` Arnd Bergmann
2021-07-23 10:33     ` Michael S. Tsirkin

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='CAK8P3a0iQ5dt_38Y9j6XCoj=n7YA+cPz7i6mjP24k9WY7QL+oA@mail.gmail.com' \
    --to=arnd@kernel.org \
    --cc=alex.bennee@linaro.org \
    --cc=bill.mills@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=info@metux.net \
    --cc=jasowang@redhat.com \
    --cc=jean-philippe@linaro.org \
    --cc=jie.deng@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=robh+dt@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    --cc=virtualization@lists.linux-foundation.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).