[PATCH 0/5] Initial steps to constify irq_chip

Christophe JAILLET
2024-11-17T09:50:00Z

struct irq_chip holds many function pointers and so, is a good
candidate for constification.

Some steps to constify these structures have already been done in 2022
with commit 393e1280f765 ("genirq: Allow irq_chip registration functions
to take a const irq_chip") and ef6e5d61eb7a ("genirq: Allow
irq_set_chip_handler_name_locked() to take a const irq_chip")

However these commits introduce some ugly casting to store some const
parameters into non-const struct members. [1] [2]

The goal of this serie is to try to go further, and eventually cleanly
constify irq_chip. As a consequence, it will increase the overall
security, because of the constification of some function pointers.

Based on elixir, it is referenced in 565 files. [3]
So, the road looks long because this structure is used in many places.

It will need to constify the return value of irq_get_chip(),
irq_data_get_irq_chip() and irq_desc_get_chip() which are widely used.
It is expected that many other functions may need to be tweaked in order
to propagate this const qualifier where needed in call chains.

So, let start somewhere and see how far we can go :)

patch 1 and 2 only update the prototypes of some functions and should be
straightforward.

The 3 other patches update some variable declaration in kernel/irq/
I have split the patches according to the way a reference to a struct
irq_chip is gotten.

This serie may be invasive and touch many places to get rid of the ugly
castings, but as least patch 1 and 2 should IMHO be merged because they
are simple and go in the right direction.

The 3 other ones, and all the oher ones that will be needed, may not
need the effort.

Before going further, feedback is aoppreciated

CJ

[1]: https://elixir.bootlin.com/linux/v6.12-rc7/source/kernel/irq/chip.c#L49
[2]: https://elixir.bootlin.com/linux/v6.12-rc7/source/include/linux/irqdesc.h#L236
[3]: https://elixir.bootlin.com/linux/v6.12-rc7/A/ident/irq_chip

Christophe JAILLET (5):
irqchip: Constify "struct irq_chip *" parameter in chained_irq_xxx()
functions
irqchip: Constify "struct irq_chip *" parameter in
cond_unmask_eoi_irq()
irqchip: Constify some direct access to irq_data->chip
irqchip: Constify some irq_desc_get_chip() usage
irqchip: Constify some irq_data_get_irq_chip() usage

include/linux/irqchip/chained_irq.h | 4 ++--
kernel/irq/chip.c | 25 +++++++++++++------------
kernel/irq/cpuhotplug.c | 2 +-
kernel/irq/debugfs.c | 2 +-
kernel/irq/manage.c | 20 ++++++++++----------
kernel/irq/migration.c | 2 +-
6 files changed, 28 insertions(+), 27 deletions(-)

--
2.47.0