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:   Fri, 21 Aug 2020 10:48:48 +0530
From:   Vinod Koul <vkoul@...nel.org>
To:     Geert Uytterhoeven <geert@...ux-m68k.org>
Cc:     Liam Beguin <liambeguin@...il.com>,
        Kishon Vijay Abraham I <kishon@...com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3 1/1] phy: tusb1210: use bitmasks to set
 VENDOR_SPECIFIC2

On 19-08-20, 15:57, Geert Uytterhoeven wrote:
> Hi Liam,
> 
> 
> On Mon, Aug 17, 2020 at 7:38 PM Liam Beguin <liambeguin@...il.com> wrote:
> > From: Liam Beguin <lvb@...hos.com>
> >
> > Start by reading the content of the VENDOR_SPECIFIC2 register and update
> > each bit field based on device properties when defined.
> >
> > The use of bit masks prevents fields from overriding each other and
> > enables users to clear bits which are set by default, like datapolarity
> > in this instance.
> >
> > Signed-off-by: Liam Beguin <lvb@...hos.com>
> > ---
> > Changes since v1:
> > - use set_mask_bits
> >
> > Changes since v2:
> > - fix missing bit shift dropped in v2
> > - rebase on 5.9-rc1
> >
> >  drivers/phy/ti/phy-tusb1210.c | 27 +++++++++++++++++----------
> >  1 file changed, 17 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/phy/ti/phy-tusb1210.c b/drivers/phy/ti/phy-tusb1210.c
> > index d8d0cc11d187..358842b5790f 100644
> > --- a/drivers/phy/ti/phy-tusb1210.c
> > +++ b/drivers/phy/ti/phy-tusb1210.c
> > @@ -14,8 +14,11 @@
> >
> >  #define TUSB1210_VENDOR_SPECIFIC2              0x80
> >  #define TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT  0
> > +#define TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK   GENMASK(3, 0)
> >  #define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT 4
> > +#define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK  GENMASK(5, 4)
> >  #define TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT     6
> > +#define TUSB1210_VENDOR_SPECIFIC2_DP_MASK      BIT(6)
> >
> >  struct tusb1210 {
> >         struct ulpi *ulpi;
> > @@ -118,23 +121,27 @@ static int tusb1210_probe(struct ulpi *ulpi)
> >          * diagram optimization and DP/DM swap.
> >          */
> >
> > +       reg = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2);
> > +
> >         /* High speed output drive strength configuration */
> > -       device_property_read_u8(&ulpi->dev, "ihstx", &val);
> > -       reg = val << TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT;
> > +       if (!device_property_read_u8(&ulpi->dev, "ihstx", &val))
> > +               reg = set_mask_bits(&reg, TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK,
> > +                                   val << TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT);
> 
> Triggered by your patches to add support for cmpxchg on u8 pointers to
> various architectures (which is a valuable goal in itself ;-), I decided
> to have a look at the underlying problem you were facing.
> 
> IMHO, using set_mask_bits() is overkill here.  That helper is meant to
> update individual bits in a variable that may be accessed concurrently,
> hence its use of cmpxchg().
> 
> In this driver, you just want to modify a local variable, by clearing a
> field, and setting some bits. No concurrency is involved.
> Perhaps using FIELD_PREP() from include/linux/bitfield.h is more
> appropriate?

Yeah i discovered the include/linux/bitfield.h and yes that looks more
apt here. u32_encode_bits() would make sense here and get rid of mask
and shift stuff too.

-- 
~Vinod

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ