Re: [PATCH RFC net-next v2 03/12] net: mdio: mdiobus_register: update validation test

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

 



Hi Russell,

Am 2023-01-03 23:19, schrieb Russell King (Oracle):
On Tue, Jan 03, 2023 at 11:21:08AM +0100, Michael Walle wrote:
Am 2023-01-03 11:13, schrieb Russell King (Oracle):
> On Wed, Dec 28, 2022 at 12:07:19AM +0100, Michael Walle wrote:
> > +	if (!bus || !bus->name)
> > +		return -EINVAL;
> > +
> > +	/* An access method always needs both read and write operations */
> > +	if ((bus->read && !bus->write) ||
> > +	    (!bus->read && bus->write) ||
> > +	    (bus->read_c45 && !bus->write_c45) ||
> > +	    (!bus->read_c45 && bus->write_c45))
>
> I wonder whether the following would be even more readable:
>
> 	if (!bus->read != !bus->write || !bus->read_c45 != !bus->write_c45)

That's what Andrew had originally. But there was a comment from Sergey [1] which I agree with. I had a hard time wrapping my head around that, so I
just listed all the possible bad cases.

The only reason I suggested it was because when looked at your code,
it also took several reads to work out what it was trying to do!

Would using !!bus->read != !!bus->write would help or make it worse,
!!ptr being the more normal way to convert something to a boolean?

IMHO that makes it even harder. But I doubt we will find an expression
that will work for everyone. I'll go with your suggestion/Andrew's first
version in the next iteration.

-michael



[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux