Re: [PATCH v4 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



...

> > @@ -762,6 +763,8 @@ static int kx022a_fifo_disable(struct kx022a_data *data)
> >   {
> >   	int ret = 0;
> >   
> > +	kfree(data->fifo_buffer);  
> 
> Should we have the kfree only after the sensor is disabled? I wonder if 
> we in theory have here a time window where the buffer is freed but the 
> measurement is still running and - with a lots of bad luck - can result 
> measurement being written to a freed buffer? Perhaps move the kfree to 
> be done only after the measurement has been stopped?
> 
> Other than that, this is looking good to me.
> 
Agreed. Even if it's not a bug as such, it is better to keep the order
of this function as close as possible to the reverse of what happens in
*_fifo_enabled() as easier to reason about if that's the case.

> > +
> >   	ret = kx022a_turn_off_lock(data);
> >   	if (ret)
> >   		return ret;
> > @@ -770,7 +773,7 @@ static int kx022a_fifo_disable(struct kx022a_data *data)
> >   	if (ret)
> >   		goto unlock_out;
> >   
> > -	ret = regmap_clear_bits(data->regmap, KX022A_REG_BUF_CNTL2,
> > +	ret = regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2,
> >   				KX022A_MASK_BUF_EN);
> >   	if (ret)
> >   		goto unlock_out;
> > @@ -801,6 +804,12 @@ static int kx022a_fifo_enable(struct kx022a_data *data)
> >   {
> >   	int ret;
> >   
> > +	data->fifo_buffer = kmalloc(data->chip_info->fifo_length *
> > +				    KX022A_FIFO_SAMPLES_SIZE_BYTES, GFP_KERNEL);
> > +
> > +	if (!data->fifo_buffer)
> > +		return -ENOMEM;
> > +
> >   	ret = kx022a_turn_off_lock(data);
> >   	if (ret)
> >   		return ret;
> > @@ -811,7 +820,7 @@ static int kx022a_fifo_enable(struct kx022a_data *data)
> >   		goto unlock_out;
> >   
> >   	/* Enable buffer */
> > -	ret = regmap_set_bits(data->regmap, KX022A_REG_BUF_CNTL2,
> > +	ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2,
> >   			      KX022A_MASK_BUF_EN);
> >   	if (ret)
> >   		goto unlock_out;

...





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux