Re: Add a "enable" sysfs attribute to the pci devices to allow userspace (Xorg) to enable devices without doing foul direct access

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

 



Arjan van de Ven <[email protected]> wrote:
>
> +static ssize_t
> +is_enabled_store(struct device *dev, struct device_attribute *attr,
> +		const char *buf, size_t count)
> +{
> +        struct pci_dev *pdev = to_pci_dev(dev);

whitespace broke

> +	if (!pdev)
> +		return 1;

Can this happen?

> +	/* this can crash the machine when done on the "wrong" device */
> +	if (!capable(CAP_SYS_ADMIN))
> +		return 1;

Don't the file's permissions suffice?

> +	if (*buf == '0')
> +		pci_disable_device(pdev);
> +
> +	if (*buf == '1')
> +		pci_enable_device(pdev);
> +
> +	return 1;

	return count;

> +}
> +
>  
>  struct device_attribute pci_dev_attrs[] = {
>  	__ATTR_RO(resource),
> @@ -101,6 +124,7 @@ struct device_attribute pci_dev_attrs[] 
>  	__ATTR_RO(irq),
>  	__ATTR_RO(local_cpus),
>  	__ATTR_RO(modalias),
> +	__ATTR(enable, 0600, is_enabled_show, is_enabled_store),
>  	__ATTR_NULL,
>  };
>  
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux