Skip to content

Commit

Permalink
irqbypass: Disallow NULL token
Browse files Browse the repository at this point in the history
A NULL token is meaningless and can only lead to unintended problems.
Error on registration with a NULL token, ignore de-registrations with
a NULL token.

Signed-off-by: Alex Williamson <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
awilliam authored and bonzini committed May 11, 2016
1 parent 0b1b1df commit b52f3ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/linux/irqbypass.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct irq_bypass_consumer;
/**
* struct irq_bypass_producer - IRQ bypass producer definition
* @node: IRQ bypass manager private list management
* @token: opaque token to match between producer and consumer
* @token: opaque token to match between producer and consumer (non-NULL)
* @irq: Linux IRQ number for the producer device
* @add_consumer: Connect the IRQ producer to an IRQ consumer (optional)
* @del_consumer: Disconnect the IRQ producer from an IRQ consumer (optional)
Expand All @@ -60,7 +60,7 @@ struct irq_bypass_producer {
/**
* struct irq_bypass_consumer - IRQ bypass consumer definition
* @node: IRQ bypass manager private list management
* @token: opaque token to match between producer and consumer
* @token: opaque token to match between producer and consumer (non-NULL)
* @add_producer: Connect the IRQ consumer to an IRQ producer
* @del_producer: Disconnect the IRQ consumer from an IRQ producer
* @stop: Perform any quiesce operations necessary prior to add/del (optional)
Expand Down
12 changes: 11 additions & 1 deletion virt/lib/irqbypass.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
struct irq_bypass_producer *tmp;
struct irq_bypass_consumer *consumer;

if (!producer->token)
return -EINVAL;

might_sleep();

if (!try_module_get(THIS_MODULE))
Expand Down Expand Up @@ -136,6 +139,9 @@ void irq_bypass_unregister_producer(struct irq_bypass_producer *producer)
struct irq_bypass_producer *tmp;
struct irq_bypass_consumer *consumer;

if (!producer->token)
return;

might_sleep();

if (!try_module_get(THIS_MODULE))
Expand Down Expand Up @@ -177,7 +183,8 @@ int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer)
struct irq_bypass_consumer *tmp;
struct irq_bypass_producer *producer;

if (!consumer->add_producer || !consumer->del_producer)
if (!consumer->token ||
!consumer->add_producer || !consumer->del_producer)
return -EINVAL;

might_sleep();
Expand Down Expand Up @@ -227,6 +234,9 @@ void irq_bypass_unregister_consumer(struct irq_bypass_consumer *consumer)
struct irq_bypass_consumer *tmp;
struct irq_bypass_producer *producer;

if (!consumer->token)
return;

might_sleep();

if (!try_module_get(THIS_MODULE))
Expand Down

0 comments on commit b52f3ed

Please sign in to comment.