在 2021/9/27 上午4:00, Krzysztof Wilczyński 写道:
[+cc Huacai and Kai-Heng as they are working in this area]
Hi,
Thank you for sending the patch over.
I assume this is simply a resend (rather than a v2), as I see no code
changes from the previous version you sent some time ago.
Sorry, I haven't receive any reply about this email, so I resend this.
Add writing attribute for boot_vga sys node,
so we can config default video display
output dynamically when there are two video
cards on a machine.
That's OK, but why are you adding this? What problem does it solve and
what is the intended user here? Might be worth adding a little bit more
details about why this new sysfs attribute is needed.
Xorg will detemine which graphics is prime output device according
boot_vga, if there are two graphics card, and we want xorg output
display to diffent graphics card, we can echo 1 to boot_vga.
I also need to ask, as I am not sure myself, whether this is OK to do after
booting during runtime? What do you think Bjorn, Huacai and Kai-Heng?
I have test this function, during runtime, if xorg's graphics output
device is card A, then we echo 1 to boot_vga of card B, and then restart
xorg, xorg will output to card B, if we want xorg always output to card
B, we can echo 1 to boot_vga of card B before xorg started in daemon
process.
Also, please correctly capitalise the subject - have a look at previous
commit messages to see how it should look like.
+static ssize_t boot_vga_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ unsigned long val;
+ struct pci_dev *pdev = to_pci_dev(dev);
+ struct pci_dev *vga_dev = vga_default_device();
+
+ if (kstrtoul(buf, 0, &val) < 0)
+ return -EINVAL;
+
+ if (val != 1)
+ return -EINVAL;
Since this is a completely new API have a look at kstrtobool() over
kstrtoul() as the former was created to handle user input more
consistently.
As I want restrict available value to 1, if we use kstrtobool(), it
will be available when user input other value.
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
Check for CAP_SYS_ADMIN is a good idea, but it has to take place before you
attempt to accept and parse a input from the user.
Krzysztof