irq: add irq_alloc_desc_between() helper
PATCH 1/1 irq: add irq_alloc_desc_between() helper
Written in response to conversation on IRC about needing to specify an upper limit on the virq value returned for some MSI interrupt controllers. Compiled only; untested
Signed-off-by Grant Likely <[email protected]>
--- include/linux/irq.h | 9 ++++++++- kernel/irq/irqdesc.c | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-)
include/linux/irq.h +8 -1
@@ -544,10 +544,17 @@ static inline struct msi_desc *irq_data_get_msi(struct irq_data *d)return d->msi_desc; } -int irq_alloc_descs (int irq,unsigned int from,unsigned int cnt,int node); +int irq_alloc_descs_between (int irq,unsigned int from,unsigned int cnt, +unsigned int max,int node);void irq_free_descs (unsigned int irq,unsigned int cnt);int irq_reserve_irqs (unsigned int from,unsigned int cnt); +static inline int irq_alloc_descs (int irq,unsigned int from,unsigned int cnt, +int node) +{ +return irq_alloc_descs_between (irq, from, cnt,0 , node); +} +static inline int irq_alloc_desc (int node) {return irq_alloc_descs (-1 ,0 ,1 , node);
kernel/irq/irqdesc.c +4 -1
@@ -322,7 +322,7 @@ void irq_free_descs(unsigned int from, unsigned int cnt)* Returns the first irq number or error code */ int __ref -irq_alloc_descs (int irq,unsigned int from,unsigned int cnt,int node) +irq_alloc_descs_between (int irq,unsigned int from,unsigned int cnt,unsigned int max,int node) {int start, ret;
@@ -337,6 +337,9 @@ irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node)if (irq >=0 && start != irq) goto err; +if (max && start + cnt >= max) + goto err; +if (start + cnt > nr_irqs) { ret =irq_expand_nr_irqs (start + cnt);if (ret)
Quoted 47 lines · Grant Likely
Written in response to conversation on IRC about needing to specify an upper limit on the virq value returned for some MSI interrupt controllers. Compiled only; untested
Signed-off-by Grant Likely <[email protected]>---
include/linux/irq.h | 9 ++++++++-
kernel/irq/irqdesc.c | 5 ++++-2 files changed, 12 insertions(+), 2 deletions(-)include/linux/irq.h +8
-1@@ -544,10 +544,17 @@ static inline struct msi_desc *irq_data_get_msi(struct irq_data *d) return d->msi_desc; } -int irq_alloc_descs (int irq,unsigned int from,unsigned int cnt,int node); +int irq_alloc_descs_between (int irq,unsigned int from,unsigned int cnt, + unsigned int max, int node); void irq_free_descs(unsigned int irq, unsigned int cnt); int irq_reserve_irqs(unsigned int from, unsigned int cnt); +static inline int irq_alloc_descs (int irq,unsigned int from,unsigned int cnt, + int node) +{ + return irq_alloc_descs_between(irq, from, cnt, 0, node); +} + static inline int irq_alloc_desc(int node) { return irq_alloc_descs(-1, 0, 1, node);kernel/irq/irqdesc.c +0
-0@@ -322,7 +322,7 @@ void irq_free_descs(unsigned int from, unsigned int cnt)* Returns the first irq number or error code */ int
__refkernel/irq/irqdesc.c +1
-1-irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node) +irq_alloc_descs_between(int irq, unsigned int from, unsigned int cnt, unsigned int max, int node){
int start, ret;
kernel/irq/irqdesc.c irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node) · line 340
Quoted 4 lines
kernel/irq/irqdesc.c +1
-0@@ -337,6 +337,9 @@ irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node) if (irq >=0 && start != irq) goto err; + if (max && start + cnt >= max)
Actually, this should be 'if (max && start + cnt > max)'
g.