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

From: Andrew Morton
Date: Sat Apr 29 2006 - 04:53:06 EST


Arjan van de Ven <arjan@xxxxxxxxxxxxxxx> 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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/