lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Thu, 9 Oct 2008 00:07:10 +0200
From:	Lennert Buytenhek <buytenh@...tstofly.org>
To:	Andy Fleming <afleming@...il.com>
Cc:	Trent Piepho <tpiepho@...escale.com>, netdev@...r.kernel.org
Subject: Re: [PATCHv3 5/5] [NET] dsa: add support for the Marvell 88E6060 switch chip

On Wed, Oct 08, 2008 at 03:20:18PM -0500, Andy Fleming wrote:

> >> > +#define REG_READ(addr, reg)                                        \
> >> > +   ({                                                      \
> >> > +           int __ret;                                      \
> >> > +                                                           \
> >> > +           __ret = reg_read(ds, addr, reg);                \
> >> > +           if (__ret < 0)                                  \
> >> > +                   return __ret;                           \
> >> > +           __ret;                                          \
> >> > +   })
> >>
> >> Macro with a hidden use of a local ('ds') and a hidden return?  The
> >> former is discouraged (but can sure save a lot of typing) but the
> >> latter seems like it's just begging to cause a missing unlock or
> >> free on an error path.
> >
> > Yeah, well, that was intentional (Nicolas Pitre suggested it, and I
> > figured it made sense to do it).  I think there are a couple more places
> > in the tree that do this, and it very much increases readability because
> > you no longer need to check the return value explicitly every single
> > time you do an MII access.
> 
> I agree with Trent, it only increases readability in the sense that
> you have to read less when scanning over the code.  To me, that is the
> least important sort of readability.  This sort of macro just creates
> hidden traps.  I know it's annoying to check that return value every
> time, but that's why we get paid the big bucks.  ;)

Well, I think I picked this up from reading kernel sources. :)
And some quick grepping shows that there's plenty of places that do
this (implicit argument and/or implicit return):

arch/powerpc/boot/libfdt/fdt_ro.c:
#define CHECK_HEADER(fdt) \
        { \
                int err; \
                if ((err = fdt_check_header(fdt)) != 0) \
                        return err; \
        }

drivers/net/e1000e/ethtool.c:
#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write)                       \
        do {                                                                   \
                if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
                        return 1;                                              \
        } while (0)

drivers/net/wireless/ath5k/eeprom.h:
define AR5K_ASSERT_ENTRY(_e, _s) do {          \
        if (_e >= _s)                           \
                return (false);                 \
} while (0)

I'd agree that there is some potential for lossage, but I wouldn't say
that the implicit return thing is all that bad.  I guess I just got
used to the construct.


> If, for some reason, the community feels this is the right way to go,
> at *least* rename the macro to make it clear that it returns on an
> error, and make ds an explicit parameter.

Explicit parameter, fine with me.

How about renaming REG_{READ,WRITE} to REG_{READ,WRITE}_RETURN_ON_ERR
or somesuch?
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ