RE: [PATCH net-next 05/12] net: dsa: b53: Use a macro to define I/O operations
> >>> +#define b53_build_op(type, op_size, val_type)\ > >>> +static inline int b53_##type##op_size(struct b53_device *dev, u8 > >page,\ > >>> + u8 reg, val_type val) > >>> \ > >>> +{ > >>> \ > >>> + int ret; > >>> \ > >>> + > >>> \ > >>> + mutex_lock(>reg_mutex); > >>> \ > >>> + ret = dev->ops->type##op_size(dev, page, reg, val); > >>> \ > >>> + mutex_unlock(>reg_mutex); > >>> \ > >>> + > >>> \ > >>> + return ret; > >>> \ > >>> } > >> > >> Why separate the 'type' and 'op_size' arguments since they > >> are always pasted together? > > > >For read/write48, the value type is u64. > > The way I read David's comment is that instead of calling the macro with > read, 48, just combine that > in a single argument: read48. I don't have a preference about that and can > respin eventually. Indeed, factoring in the type is harder because reads want 'u64 *' not 'u64'. While that could be factored, it would take more source lines and make things very obfuscated. David
RE: [PATCH net-next 05/12] net: dsa: b53: Use a macro to define I/O operations
On September 19, 2017 7:19:35 AM PDT, Vivien Didelotwrote: >Hi David, > >David Laight writes: > >> From: Florian Fainelli >>> Sent: 18 September 2017 22:41 >>> Instead of repeating the same pattern: acquire mutex, read/write, >release >>> mutex, define a macro: b53_build_op() which takes the type >(read|write), I/O >>> size, and value (scalar or pointer). This helps with fixing bugs >that could >>> exit (e.g: missing barrier, lock etc.). >> >>> +#define b53_build_op(type, op_size, val_type) \ >>> +static inline int b53_##type##op_size(struct b53_device *dev, u8 >page, \ >>> + u8 reg, val_type val) >>> \ >>> +{ >>> \ >>> + int ret; >>> \ >>> + >>> \ >>> + mutex_lock(>reg_mutex); >>> \ >>> + ret = dev->ops->type##op_size(dev, page, reg, val); >>> \ >>> + mutex_unlock(>reg_mutex); >>> \ >>> + >>> \ >>> + return ret; >>> \ >>> } >> >> Why separate the 'type' and 'op_size' arguments since they >> are always pasted together? > >For read/write48, the value type is u64. The way I read David's comment is that instead of calling the macro with read, 48, just combine that in a single argument: read48. I don't have a preference about that and can respin eventually. -- Florian
RE: [PATCH net-next 05/12] net: dsa: b53: Use a macro to define I/O operations
Hi David, David Laightwrites: > From: Florian Fainelli >> Sent: 18 September 2017 22:41 >> Instead of repeating the same pattern: acquire mutex, read/write, release >> mutex, define a macro: b53_build_op() which takes the type (read|write), I/O >> size, and value (scalar or pointer). This helps with fixing bugs that could >> exit (e.g: missing barrier, lock etc.). > >> +#define b53_build_op(type, op_size, val_type) \ >> +static inline int b53_##type##op_size(struct b53_device *dev, u8 page, >> \ >> + u8 reg, val_type val) >> \ >> +{ >> \ >> +int ret; >> \ >> + >> \ >> +mutex_lock(>reg_mutex); >> \ >> +ret = dev->ops->type##op_size(dev, page, reg, val); >> \ >> +mutex_unlock(>reg_mutex); >> \ >> + >> \ >> +return ret; >> \ >> } > > Why separate the 'type' and 'op_size' arguments since they > are always pasted together? For read/write48, the value type is u64. Thanks, Vivien
RE: [PATCH net-next 05/12] net: dsa: b53: Use a macro to define I/O operations
From: Florian Fainelli > Sent: 18 September 2017 22:41 > Instead of repeating the same pattern: acquire mutex, read/write, release > mutex, define a macro: b53_build_op() which takes the type (read|write), I/O > size, and value (scalar or pointer). This helps with fixing bugs that could > exit (e.g: missing barrier, lock etc.). > +#define b53_build_op(type, op_size, val_type)\ > +static inline int b53_##type##op_size(struct b53_device *dev, u8 page, > \ > + u8 reg, val_type val) > \ > +{ > \ > + int ret; > \ > + > \ > + mutex_lock(>reg_mutex); > \ > + ret = dev->ops->type##op_size(dev, page, reg, val); > \ > + mutex_unlock(>reg_mutex); > \ > + > \ > + return ret; > \ > } Why separate the 'type' and 'op_size' arguments since they are always pasted together? David
Re: [PATCH net-next 05/12] net: dsa: b53: Use a macro to define I/O operations
Hi Florian, Florian Fainelliwrites: > Instead of repeating the same pattern: acquire mutex, read/write, release > mutex, define a macro: b53_build_op() which takes the type (read|write), I/O > size, and value (scalar or pointer). This helps with fixing bugs that could > exit (e.g: missing barrier, lock etc.). > > Signed-off-by: Florian Fainelli Reviewed-by: Vivien Didelot