Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp714653rwe; Thu, 1 Sep 2022 06:40:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR4qAq+8C31R01XeLce8wgRT33dd6JJrhNYIace7lWHw/E84KVnk67uM62gFO+JEeE34dpWX X-Received: by 2002:a63:fc50:0:b0:41b:bbb8:ee36 with SMTP id r16-20020a63fc50000000b0041bbbb8ee36mr25660965pgk.20.1662039652419; Thu, 01 Sep 2022 06:40:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662039652; cv=none; d=google.com; s=arc-20160816; b=Xsapqs/Ixi05LDn5dcP7nKlagjY6rToZy4m0WmleQAhBr8B65ROWcUlBT7WCnIpxxm fNe/NHtJw4sMQoM1geB8uhLMOpSO2Cye2KvPMSlkBHOzwqplmvpp0oFKspOmbkzsYOqO A8vd9ODdWBBIQERuun8XkZa93Y5AseyHfZkP2Gu66wR+IAkRjY/l6NL+TsaJZoAVAyGN PZAAhgGp6Z+J1rHqTv0K3yehaI1s2bzLww7w2Ln0qz0D2JjfFT3h/WyAFyt3TnpNdBrE /PymIX3UGqGW/ixJPia6whtP5mzKRdWVK7Lduuot3qnHUSURIyznfmTJLCq0PhJDd92C ao9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=hpJ9v7gTg2XqLO17BDRT+rRYIs/UZ/N5FSMQyX2xU/U=; b=ZNseuYL2OKsRthMh5ABsuAW7hAtfHHsfuriN/jKlslXxWmd8kvSCrmu1VtdC7YG20l sx+u3/x+wMVUYK8C91R9a/zDRRovGIf7Ph3DsBDiTItNBN+QTrfJwg+17n22umPz/uSt iBai3mPJcXZotWrAFEBEt5ngHXXWGX7e/PG1QcSh5z/X5wO5AO/IcYoSaosG9/p+LmtF 9DmkuB2PfhT+dgTg/hzCsR0PylpZzgLS7kKTMpGSnhNj/XjESft+jFCnvvNER6aO2Gkq MEC5iYwJYpzI+hvPzoXgZsa7Ab5Lu45JwsXhfa29OPktJibdVbWNaHC0A3uiS2ID99XS HKcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 200-20020a6300d1000000b0043030116f93si4336162pga.640.2022.09.01.06.40.40; Thu, 01 Sep 2022 06:40:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232939AbiIANTF (ORCPT + 99 others); Thu, 1 Sep 2022 09:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234270AbiIANSn (ORCPT ); Thu, 1 Sep 2022 09:18:43 -0400 Received: from cstnet.cn (smtp23.cstnet.cn [159.226.251.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D78A079EF8 for ; Thu, 1 Sep 2022 06:15:52 -0700 (PDT) Received: from localhost.localdomain (unknown [124.16.138.126]) by APP-03 (Coremail) with SMTP id rQCowADHvFFbsBBjmkMbAA--.34673S2; Thu, 01 Sep 2022 21:15:08 +0800 (CST) From: Jiasheng Jiang To: gregkh@linuxfoundation.org Cc: hdegoede@redhat.com, arnd@arndb.de, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v3 1/2] virt: vbox: Add check for device_create_file Date: Thu, 1 Sep 2022 21:15:06 +0800 Message-Id: <20220901131506.3550180-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: rQCowADHvFFbsBBjmkMbAA--.34673S2 X-Coremail-Antispam: 1UD129KBjvJXoW7CFWxGw13uryUAr4UXFyUAwb_yoW8tw4Upa 93Ja4SvF4fGa1UWw42ya4jva45uw1rG3yxZrZ3Gw4Fgr9xA39FvFWDCFWjyr95GFZ5WF4F qr1UtryrCFWUuF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyl14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1j6r1xM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxAIw28IcxkI7VAKI48J MxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4 v20xvaj40_WFyUJVCq3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E 14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU5WlkUUUUU X-Originating-IP: [124.16.138.126] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As device_create_file() can return error number, it should be better to check the return value and deal with the exception. Moreover, this driver should be using an attribute group. Fixes: 0ba002bc4393 ("virt: Add vboxguest driver for Virtual Box Guest integration") Signed-off-by: Jiasheng Jiang --- Change log: v2-> v3: 1. Switch to use an attribute group. v1 -> v2: 1. Use gdev->dev instead of dev. 2. Remove file when creation failed. --- drivers/virt/vboxguest/vboxguest_linux.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/virt/vboxguest/vboxguest_linux.c b/drivers/virt/vboxguest/vboxguest_linux.c index 4ccfd30c2a30..6fc81347ae72 100644 --- a/drivers/virt/vboxguest/vboxguest_linux.c +++ b/drivers/virt/vboxguest/vboxguest_linux.c @@ -270,6 +270,13 @@ static ssize_t host_features_show(struct device *dev, static DEVICE_ATTR_RO(host_version); static DEVICE_ATTR_RO(host_features); +static struct attribute *vbg_pci_attrs[] = { + &dev_attr_host_version.attr, + &dev_attr_host_features.attr, + NULL, +}; +ATTRIBUTE_GROUPS(vbg_pci); + /** * Does the PCI detection and init of the device. * @@ -390,8 +397,6 @@ static int vbg_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) } pci_set_drvdata(pci, gdev); - device_create_file(dev, &dev_attr_host_version); - device_create_file(dev, &dev_attr_host_features); vbg_info("vboxguest: misc device minor %d, IRQ %d, I/O port %x, MMIO at %pap (size %pap)\n", gdev->misc_device.minor, pci->irq, gdev->io_port, @@ -422,8 +427,6 @@ static void vbg_pci_remove(struct pci_dev *pci) mutex_unlock(&vbg_gdev_mutex); free_irq(pci->irq, gdev); - device_remove_file(gdev->dev, &dev_attr_host_features); - device_remove_file(gdev->dev, &dev_attr_host_version); misc_deregister(&gdev->misc_device_user); misc_deregister(&gdev->misc_device); vbg_core_exit(gdev); @@ -488,6 +491,7 @@ MODULE_DEVICE_TABLE(pci, vbg_pci_ids); static struct pci_driver vbg_pci_driver = { .name = DEVICE_NAME, + .dev_groups = vbg_pci_groups, .id_table = vbg_pci_ids, .probe = vbg_pci_probe, .remove = vbg_pci_remove, -- 2.25.1