conditional operator ?: usage (Linux kernel)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I don't mind the use of ?: for choosing values, but it seems odd to me
to use it for calling functions, as in:  [from drivers/clocksource/timer-of.c),
line 28 in Linux 5.4-rc1):

	of_irq->percpu ? free_percpu_irq(of_irq->irq, clkevt) :
		free_irq(of_irq->irq, clkevt);

where free_percpu_irq() and free_irq() are function calls but not of exactly
the same type, so sparse (0.6.1-rc1) doesn't like it:

../drivers/clocksource/timer-of.c:28:24: error: incompatible types in conditional expression (different types):
../drivers/clocksource/timer-of.c:28:24:    void
../drivers/clocksource/timer-of.c:28:24:    void const *
  CC      drivers/clocksource/timer-of.o


gcc doesn't complain about the ?: usage.  Is sparse correct here or is it being
too strict?

I would have just coded the 2 functions calls as
	if (of_irq->percpu)
		free_percpu_irq(of_irq->irq, clkevt);
	else
		free_irq(of_irq->irq, clkevt);

cheers.
-- 
~Randy



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux