Re: [PATCH] staging: dgnc: take lock when storing value in dgnc_poll_tick

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

 



On Tue, Aug 18, 2015 at 08:37:21PM +0100, Salah Triki wrote:
> @@ -57,11 +57,17 @@ static ssize_t dgnc_driver_pollrate_store(struct device_driver *ddp,
>  					  const char *buf, size_t count)
>  {
>  	int ret;
> +	unsigned long flags;
>  
> +	spin_lock_irqsave(&dgnc_poll_lock, flags);
>  	ret = sscanf(buf, "%d\n", &dgnc_poll_tick);
>  	if (ret != 1)
> -		return -EINVAL;
> -	return count;
> +		ret = -EINVAL;
> +	else
> +		ret = count;
> +	spin_unlock_irqrestore(&dgnc_poll_lock, flags);
> +
> +	return ret;
>  }

Looks basically ok, but I wonder if it would be better to use a
temporary buffer for the sscanf.

	unsigned long flags;
	int tick;
	int ret;

	ret = sscanf(buf, "%d\n", &tick);
	if (ret != 1)
		return -EINVAL;

	spin_lock_irqsave(&dgnc_poll_lock, flags);
	dgnc_poll_tick = tick;
	spin_unlock_irqrestore(&dgnc_poll_lock, flags);

	return count;

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux