Skip to content

Commit 61bf992

Browse files
committed
genirq/msi: Add size info to struct msi_domain_info
To allow proper range checking especially for dynamic allocations add a size field to struct msi_domain_info. If the field is 0 then the size is unknown or unlimited (up to MSI_MAX_INDEX) to provide backwards compability. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Acked-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20221124232325.501144862@linutronix.de
1 parent ebca439 commit 61bf992

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

include/linux/msi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ struct msi_domain_ops {
422422
* struct msi_domain_info - MSI interrupt domain data
423423
* @flags: Flags to decribe features and capabilities
424424
* @bus_token: The domain bus token
425+
* @hwsize: The hardware table size or the software index limit.
426+
* If 0 then the size is considered unlimited and
427+
* gets initialized to the maximum software index limit
428+
* by the domain creation code.
425429
* @ops: The callback data structure
426430
* @chip: Optional: associated interrupt chip
427431
* @chip_data: Optional: associated interrupt chip data
@@ -433,6 +437,7 @@ struct msi_domain_ops {
433437
struct msi_domain_info {
434438
u32 flags;
435439
enum irq_domain_bus_token bus_token;
440+
unsigned int hwsize;
436441
struct msi_domain_ops *ops;
437442
struct irq_chip *chip;
438443
void *chip_data;

kernel/irq/msi.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,17 @@ struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,
772772
{
773773
struct irq_domain *domain;
774774

775+
if (info->hwsize > MSI_XA_DOMAIN_SIZE)
776+
return NULL;
777+
778+
/*
779+
* Hardware size 0 is valid for backwards compatibility and for
780+
* domains which are not backed by a hardware table. Grant the
781+
* maximum index space.
782+
*/
783+
if (!info->hwsize)
784+
info->hwsize = MSI_XA_DOMAIN_SIZE;
785+
775786
msi_domain_update_dom_ops(info);
776787
if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS)
777788
msi_domain_update_chip_ops(info);

0 commit comments

Comments
 (0)