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]
Message-ID: <20200106144437.615698c1@xps13>
Date:   Mon, 6 Jan 2020 14:44:37 +0100
From:   Miquel Raynal <miquel.raynal@...tlin.com>
To:     Andy Shevchenko <andy.shevchenko@...il.com>
Cc:     Linus Walleij <linus.walleij@...aro.org>,
        Bartosz Golaszewski <bgolaszewski@...libre.com>,
        Thierry Reding <thierry.reding@...il.com>,
        Uwe Kleine-König 
        <u.kleine-koenig@...gutronix.de>,
        "open list:GPIO SUBSYSTEM" <linux-gpio@...r.kernel.org>,
        linux-pwm@...r.kernel.org,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Thomas Petazzoni <thomas.petazzoni@...tlin.com>
Subject: Re: [PATCH v4] gpio: pca953x: Add Maxim MAX7313 PWM support

Hi Andy,

> >  #define PCA_INT                        BIT(8)
> >  #define PCA_PCAL               BIT(9)  
> 
> > +#define MAX_PWM                        BIT(10)  
> 
> Use same prefix.

I am not sure it is relevant here, I think showing the specificity of
the MAXIM PWM is okay.

> 
> ...
> 
> > +#define PWM_MAX_COUNT 16
> > +#define PWM_PER_REG 2  
> 
> > +#define PWM_BITS_PER_REG (8 / PWM_PER_REG)  
> 
> Can we simple put 4 here?
> 

Fine

> ...
> 
> > +#define PWM_INTENSITY_MASK GENMASK(PWM_BITS_PER_REG - 1, 0)  
> 
> Please use plain numbers for the GENMASK() arguments.

Ok

> 
> ...
> 
> > +struct max7313_pwm_data {
> > +       struct gpio_desc *desc;
> > +};  
> 
> Are you plan to extend this? Can we directly use struct gpio_desc pointer?

I'm not a fan of this method at all, I think it is better practice to
keep a container in this case, which can be easily extended when needed.

> 
> ...
> 
> > +       if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE &&
> > +           chip->driver_data & MAX_PWM) {  
> 
> Can't we simple check only for a flag for now?

I don't get it. You just want the driver_data & MAX_PWM check?

> 
> > +               if (reg >= MAX7313_MASTER &&
> > +                   reg < (MAX7313_INTENSITY + bank_sz))
> > +                       return true;
> > +       }  
> 
> ...
> 
> > +       if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE &&
> > +           chip->driver_data & MAX_PWM) {
> > +               if (reg >= MAX7313_MASTER &&
> > +                   reg < (MAX7313_INTENSITY + bank_sz))
> > +                       return true;
> > +       }  
> 
> This is a duplicate from above. Need a helper?

Perhaps!

> 
> ...
> 
> > +/*
> > + * Max7313 PWM specific methods
> > + *
> > + * Limitations:
> > + * - Does not support a disabled state
> > + * - Period fixed to 31.25ms
> > + * - Only supports normal polarity
> > + * - Some glitches cannot be prevented
> > + */  
> 
> Can we have below in a separate file and attach it to the gpio-pca953x
> code iff CONFIG_PWM != n?

I'll check, why not.

> 
> ...
> 
> > +       mutex_lock(&pca_chip->i2c_lock);  
> 
> > +       regmap_read(pca_chip->regmap, reg, &val);  
> 
> No error check?
> 
> > +       mutex_unlock(&pca_chip->i2c_lock);  
> 
> ...
> 
> > +       if (shift)  
> 
> Redundant.

Ok

> 
> > +               val >>= shift;  
> 
> ...
> 
> > +       mutex_lock(&pca_chip->i2c_lock);
> > +       regmap_read(pca_chip->regmap, reg, &output);
> > +       mutex_unlock(&pca_chip->i2c_lock);  
> 
> No error check?
> 
> ...
> 
> > +       mutex_lock(&pca_chip->i2c_lock);
> > +       regmap_read(pca_chip->regmap, reg, &output);
> > +       mutex_unlock(&pca_chip->i2c_lock);  
> 
> No error check?
> 
> ...
> 
> > +static int max7313_pwm_request(struct pwm_chip *chip,
> > +                              struct pwm_device *pwm)
> > +{
> > +       struct max7313_pwm *max_pwm = to_max7313_pwm(chip);
> > +       struct pca953x_chip *pca_chip = to_pca953x(max_pwm);
> > +       struct max7313_pwm_data *data;
> > +       struct gpio_desc *desc;
> > +
> > +       desc = gpiochip_request_own_desc(&pca_chip->gpio_chip, pwm->hwpwm,
> > +                                        "max7313-pwm", GPIO_ACTIVE_HIGH, 0);
> > +       if (IS_ERR(desc)) {  
> 
> > +               dev_err(&pca_chip->client->dev,  
> 
> Can't we get to struct device easily?
> If it's possible maybe we could move next line to this one?

I'll try.

> 
> > +                       "pin already in use (probably as GPIO): %ld\n",
> > +                       PTR_ERR(desc));
> > +               return PTR_ERR(desc);
> > +       }  
> 
> > +       return 0;
> > +}  
> 
> ...
> 
> > +       if (intensity)
> > +               set_bit(pwm->hwpwm, max_pwm->active_pwm);
> > +       else
> > +               clear_bit(pwm->hwpwm, max_pwm->active_pwm);  
> 
> assign_bit()

Nice!

> 
> By the way, do you really need it to be atomic? Perhaps __asign_bit()?

Maybe not, indeed.

> 
> ...
> 
> > +       active = bitmap_weight(max_pwm->active_pwm, PWM_MAX_COUNT);  
> 
> > +       if (!active)  
> 
> In this case more readable will be active == 0 since you compare this
> to the exact value.
> 

"if (!active)" is read "if not active" which is IMHO very descriptive!

I'll correct most of your comments and send a v5.

Thanks,
Miquèl

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ