diff mbox series

virtio: i2c: Check notifier helpers for VIRTIO_CONFIG_IRQ_IDX

Message ID 89d47285e882a99a0513411edcc96aa575512f13.1681710993.git.viresh.kumar@linaro.org (mailing list archive)
State New, archived
Headers show
Series virtio: i2c: Check notifier helpers for VIRTIO_CONFIG_IRQ_IDX | expand

Commit Message

Viresh Kumar April 17, 2023, 6:02 a.m. UTC
Since the driver doesn't support interrupts, we must return early when
index is set to VIRTIO_CONFIG_IRQ_IDX.

Fixes: 544f0278afca ("virtio: introduce macro VIRTIO_CONFIG_IRQ_IDX")
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 hw/virtio/vhost-user-i2c.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Philippe Mathieu-Daudé April 17, 2023, 7:36 a.m. UTC | #1
On 17/4/23 08:02, Viresh Kumar wrote:
> Since the driver doesn't support interrupts, we must return early when
> index is set to VIRTIO_CONFIG_IRQ_IDX.
> 
> Fixes: 544f0278afca ("virtio: introduce macro VIRTIO_CONFIG_IRQ_IDX")
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>   hw/virtio/vhost-user-i2c.c | 20 ++++++++++++++++++++
>   1 file changed, 20 insertions(+)
> 
> diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c
> index 60eaf0d95be0..45100a24953c 100644
> --- a/hw/virtio/vhost-user-i2c.c
> +++ b/hw/virtio/vhost-user-i2c.c
> @@ -128,6 +128,16 @@ static void vu_i2c_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask)
>   {
>       VHostUserI2C *i2c = VHOST_USER_I2C(vdev);
>   
> +    /*
> +     * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1
> +     * as the Marco of configure interrupt's IDX, If this driver does not

Copy/paste of pre-existing comment, still I wonder who is "the Marco of 
configure" :P

> +     * support, the function will return
> +     */
Viresh Kumar April 17, 2023, 7:42 a.m. UTC | #2
On 17-04-23, 09:36, Philippe Mathieu-Daudé wrote:
> On 17/4/23 08:02, Viresh Kumar wrote:
> > Since the driver doesn't support interrupts, we must return early when
> > index is set to VIRTIO_CONFIG_IRQ_IDX.
> > 
> > Fixes: 544f0278afca ("virtio: introduce macro VIRTIO_CONFIG_IRQ_IDX")
> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> > ---
> >   hw/virtio/vhost-user-i2c.c | 20 ++++++++++++++++++++
> >   1 file changed, 20 insertions(+)
> > 
> > diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c
> > index 60eaf0d95be0..45100a24953c 100644
> > --- a/hw/virtio/vhost-user-i2c.c
> > +++ b/hw/virtio/vhost-user-i2c.c
> > @@ -128,6 +128,16 @@ static void vu_i2c_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask)
> >   {
> >       VHostUserI2C *i2c = VHOST_USER_I2C(vdev);
> > +    /*
> > +     * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1
> > +     * as the Marco of configure interrupt's IDX, If this driver does not
> 
> Copy/paste of pre-existing comment, still I wonder who is "the Marco of
> configure" :P
> 
> > +     * support, the function will return
> > +     */

Yeah the comment could be improved, I didn't touch it as it was
written this way for many drivers :)

Maybe a simple comment like is all we need:

/*
 * We don't support interrupts, return early if index is set to
 * VIRTIO_CONFIG_IRQ_IDX.
 */
Alex Bennée April 17, 2023, 9:21 a.m. UTC | #3
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> On 17/4/23 08:02, Viresh Kumar wrote:
>> Since the driver doesn't support interrupts, we must return early when
>> index is set to VIRTIO_CONFIG_IRQ_IDX.
>> Fixes: 544f0278afca ("virtio: introduce macro
>> VIRTIO_CONFIG_IRQ_IDX")
>> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
>> ---
>>   hw/virtio/vhost-user-i2c.c | 20 ++++++++++++++++++++
>>   1 file changed, 20 insertions(+)
>> diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c
>> index 60eaf0d95be0..45100a24953c 100644
>> --- a/hw/virtio/vhost-user-i2c.c
>> +++ b/hw/virtio/vhost-user-i2c.c
>> @@ -128,6 +128,16 @@ static void vu_i2c_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask)
>>   {
>>       VHostUserI2C *i2c = VHOST_USER_I2C(vdev);
>>   +    /*
>> +     * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1
>> +     * as the Marco of configure interrupt's IDX, If this driver does not
>
> Copy/paste of pre-existing comment, still I wonder who is "the Marco
> of configure" :P
>
>> +     * support, the function will return
>> +     */

First patch of my last VirtIO series fixes these all up.
diff mbox series

Patch

diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c
index 60eaf0d95be0..45100a24953c 100644
--- a/hw/virtio/vhost-user-i2c.c
+++ b/hw/virtio/vhost-user-i2c.c
@@ -128,6 +128,16 @@  static void vu_i2c_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask)
 {
     VHostUserI2C *i2c = VHOST_USER_I2C(vdev);
 
+    /*
+     * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1
+     * as the Marco of configure interrupt's IDX, If this driver does not
+     * support, the function will return
+     */
+
+    if (idx == VIRTIO_CONFIG_IRQ_IDX) {
+        return;
+    }
+
     vhost_virtqueue_mask(&i2c->vhost_dev, vdev, idx, mask);
 }
 
@@ -135,6 +145,16 @@  static bool vu_i2c_guest_notifier_pending(VirtIODevice *vdev, int idx)
 {
     VHostUserI2C *i2c = VHOST_USER_I2C(vdev);
 
+    /*
+     * Add the check for configure interrupt, Use VIRTIO_CONFIG_IRQ_IDX -1
+     * as the Marco of configure interrupt's IDX, If this driver does not
+     * support, the function will return
+     */
+
+    if (idx == VIRTIO_CONFIG_IRQ_IDX) {
+        return false;
+    }
+
     return vhost_virtqueue_pending(&i2c->vhost_dev, idx);
 }