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] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 4 Nov 2020 14:14:24 +0200
From:   Vladimir Oltean <olteanv@...il.com>
To:     Marek BehĂșn <kabel@...nel.org>
Cc:     netdev@...r.kernel.org, linux-usb@...r.kernel.org,
        Hayes Wang <hayeswang@...ltek.com>
Subject: Re: [PATCH net-next 3/5] r8152: add MCU typed read/write functions

On Wed, Nov 04, 2020 at 12:10:53PM +0100, Marek BehĂșn wrote:
> > I'm not sure it's worth the change :(
> > Let's put it another way, your diffstat has 338 insertions and 335
> > deletions. Aka you're saving 3 lines overall.
> > With this new approach that doesn't use token concatenation at all,
> > you're probably not saving anything at all.
> > Also, I'm not sure that you need to make the functions inline. The
> > compiler should be smart enough to not generate functions for
> > usb_ocp_read_byte etc. You can check with
> > "make drivers/net/usb/r8152.lst".
> 
> Vladimir, the purpose of this patch isn't to save lines, but to save us
> from always writing MCU_TYPE_USB / MCU_TYPE_PLA.
> It just transforms forms of
>   ocp_read_word(tp, MCU_TYPE_USB, idx);
>   ocp_write_dword(tp, MCU_TYPE_PLA, idx, val);
> into
>   usb_ocp_read_word(tp, idx);
>   pla_ocp_write_dword(tp, idx, val);
> 
> The fifth patch of this series saves lines by adding _modify functions,
> to transform
>   val = *_read(idx);
>   val &= ~clr;
>   val |= set;
>   *_write(idx, val);
> into
>   *_modify(idx, clr, set);
> 

So if the point isn't to save lines, then why don't you go for something
trivial?

static void ocp_modify_byte(struct r8152 *tp, u16 type, u16 index, u8 clr,
			    u8 set)
{
	u8 val = ocp_read_byte(tp, type, index);

	ocp_write_byte(tp, type, index, (val & ~clr) | set);
}

static void ocp_modify_word(struct r8152 *tp, u16 type, u16 index, u16 clr,
			    u16 set)
{
	u16 val = ocp_read_word(tp, type, index);

	ocp_write_word(tp, type, index, (val & ~clr) | set);
}

static void ocp_modify_dword(struct r8152 *tp, u16 type, u16 index, u32 clr,
			     u32 set)
{
	u32 val = ocp_read_dword(tp, type, index);

	ocp_write_dword(tp, type, index, (val & ~clr) | set);
}

#define pla_ocp_read_byte(tp, index)				\
	ocp_read_byte(tp, MCU_TYPE_PLA, index)
#define pla_ocp_write_byte(tp, index, data)			\
	ocp_write_byte(tp, MCU_TYPE_PLA, index, data)
#define pla_ocp_modify_byte(tp, index, clr, set)		\
	ocp_modify_byte(tp, MCU_TYPE_PLA, index, clr, set)
#define pla_ocp_read_word(tp, index)				\
	ocp_read_word(tp, MCU_TYPE_PLA, index)
#define pla_ocp_write_word(tp, index, data)			\
	ocp_write_word(tp, MCU_TYPE_PLA, index, data)
#define pla_ocp_modify_word(tp, index, clr, set)		\
	ocp_modify_word(tp, MCU_TYPE_PLA, index, clr, set)
#define pla_ocp_read_dword(tp, index)				\
	ocp_read_dword(tp, MCU_TYPE_PLA, index)
#define pla_ocp_write_dword(tp, index, data)			\
	ocp_write_dword(tp, MCU_TYPE_PLA, index, data)
#define pla_ocp_modify_dword(tp, index, clr, set)		\
	ocp_modify_dword(tp, MCU_TYPE_PLA, index, clr, set)

#define usb_ocp_read_byte(tp, index)				\
	ocp_read_byte(tp, MCU_TYPE_USB, index)
#define usb_ocp_write_byte(tp, index, data)			\
	ocp_write_byte(tp, MCU_TYPE_USB, index, data)
#define usb_ocp_modify_byte(tp, index, clr, set)		\
	ocp_modify_byte(tp, MCU_TYPE_USB, index, clr, set)
#define usb_ocp_read_word(tp, index)				\
	ocp_read_word(tp, MCU_TYPE_USB, index)
#define usb_ocp_write_word(tp, index, data)			\
	ocp_write_word(tp, MCU_TYPE_USB, index, data)
#define usb_ocp_modify_word(tp, index, clr, set)		\
	ocp_modify_word(tp, MCU_TYPE_USB, index, clr, set)
#define usb_ocp_read_dword(tp, index)				\
	ocp_read_dword(tp, MCU_TYPE_USB, index)
#define usb_ocp_write_dword(tp, index, data)			\
	ocp_write_dword(tp, MCU_TYPE_USB, index, data)
#define usb_ocp_modify_dword(tp, index, clr, set)		\
	ocp_modify_dword(tp, MCU_TYPE_USB, index, clr, set)

To my eyes this is easier to digest.

That is, unless you want to go for function pointers and have separate
structures for PLA and USB...

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ