Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3579372pxb; Sun, 26 Sep 2021 20:14:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0QDC9DMFj94zIjhQGjaGr4IszNhnCtnlx6RcWOMTMhS6YtqKa7h/t5jjm9Z23O+azDfOq X-Received: by 2002:a17:90b:e0e:: with SMTP id ge14mr804489pjb.138.1632712490418; Sun, 26 Sep 2021 20:14:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632712490; cv=none; d=google.com; s=arc-20160816; b=vt18U9krFNsuXtXpVXyYm3p/LTBC5S+B39jYnznZKm6Ng+j+xQ/Okni8dvNwnjQLj5 z/rWMJkEO0lL/QXEqxHgJL4ujIr7kdfa0S2SqS2YcwdCCLmqgQfzx70OM6TOkPbEPZ/q IpKLrOGWbec7/6daUPZf5hGSX7wQxxQtz1R3DkQvwb//GM0wO0GTbuMACc2GPzxF4yCc LylMbgbikFyRKBSE1zpmSsFPK9E8KvTNCQNsqQY3tbZdulnnweroJItYiwDB+EjvpWdb vhMyM4WnqhDkeU54b5lDK/Bq36D4rBdAsLf5OA33k9logbHP3SyT3+Gw/MwwR7gjhHm8 PJUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=+AvASHfH6F97QhJQxQvl9ORdaIoJ3v7RWrt6c42C74U=; b=V065/q8Jk4fTP/pruVNPKeSO8JK61lAYsKZ/+3wsFoP6SFpIHeN3ChZykW7lB+RSCU BNcntlngPLFVGp21OagJf5ccCcQAkgN5XA0XBsjih4mKyIn5Beh+lll0kZcRCguU1k5d WFJc3D0p56EDBb2dZz6MW+WdrlTAMF8U2OU7FdP112jjf9n/VsCgVA/ON+s8unFIdLo9 77pDGWhYUKa48ethGFAqoz+rQdo/VGrXOPwnK+twOLR4udjOmNrhonQnyhL1L0NZlE4Z mkTXi88+miXX+Hqw8onlgrG9B3qJv45ZvDGCOT3aaEI3jmEWe6wy6082X8SBAhYluDc5 BSwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r11si17487856plr.438.2021.09.26.20.14.37; Sun, 26 Sep 2021 20:14:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232535AbhI0DIX (ORCPT + 99 others); Sun, 26 Sep 2021 23:08:23 -0400 Received: from mailgw.kylinos.cn ([123.150.8.42]:19660 "EHLO nksmu.kylinos.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232526AbhI0DIU (ORCPT ); Sun, 26 Sep 2021 23:08:20 -0400 X-UUID: 210ab987e7ee4120a6f881761a7c795a-20210927 X-CPASD-INFO: 17c0c1b8280543bc86431ceff58f605f@eoedUJBjkGheWHKBg3atnVhnZGNhj4W 1qG9YlmRgYYaVhH5xTWJsXVKBfG5QZWNdYVN_eGpQYl9gZFB5i3-XblBgXoZgUZB3gHmdUJNfkg== X-CPASD-FEATURE: 0.0 X-CLOUD-ID: 17c0c1b8280543bc86431ceff58f605f X-CPASD-SUMMARY: SIP:-1,APTIP:-2.0,KEY:0.0,FROMBLOCK:1,EXT:0.0,OB:0.0,URL:-5,T VAL:168.0,ESV:0.0,ECOM:-5.0,ML:0.0,FD:0.0,CUTS:186.0,IP:-2.0,MAL:0.0,ATTNUM:0 .0,PHF:-5.0,PHC:-5.0,SPF:4.0,EDMS:-3,IPLABEL:4480.0,FROMTO:0,AD:0,FFOB:0.0,CF OB:0.0,SPC:0.0,SIG:-5,AUF:4,DUF:14797,ACD:54,DCD:156,SL:0,AG:0,CFC:0.624,CFSR :0.051,UAT:0,RAF:2,VERSION:2.3.4 X-CPASD-ID: 210ab987e7ee4120a6f881761a7c795a-20210927 X-CPASD-BLOCK: 1000 X-CPASD-STAGE: 1, 1 X-UUID: 210ab987e7ee4120a6f881761a7c795a-20210927 X-User: lizhenneng@kylinos.cn Received: from [172.20.108.41] [(116.128.244.169)] by nksmu.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES128-GCM-SHA256 128/128) with ESMTP id 679021459; Mon, 27 Sep 2021 11:03:53 +0800 Subject: Re: [PATCH] PCI/sysfs: add write attribute for boot_vga To: =?UTF-8?Q?Krzysztof_Wilczy=c5=84ski?= Cc: Bjorn Helgaas , Huacai Chen , Kai-Heng Feng , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210926071539.636644-1-lizhenneng@kylinos.cn> From: =?UTF-8?B?5p2O55yf6IO9?= Message-ID: Date: Mon, 27 Sep 2021 11:06:38 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 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