From patchwork Fri Oct 6 14:30:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 149275 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp372880vqo; Fri, 6 Oct 2023 07:31:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwO1RJUb3MGaWsc+ABZCsRx9AHF2XKlkKmJnUm7Yt8kgUQziUpu4/R5wSCnp53zsY9znvQ X-Received: by 2002:a17:902:d716:b0:1c7:251c:c250 with SMTP id w22-20020a170902d71600b001c7251cc250mr7626202ply.25.1696602691179; Fri, 06 Oct 2023 07:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696602691; cv=none; d=google.com; s=arc-20160816; b=rAEyDUv+iNTvK1zRlw/3Rxf+PFjHE8OrJmDGRa0zTLR4lHYdyDlcr0emHFFeUo9oBL F/+4RQhcIviRGR3qWRejk/JAMJnc1BSgJtJ3i8nRfs3gLNQX/9WQydJ4Fznhe94bXqSg AVm2UwfVE4w+Ig1EXs7t4q/E5Flvt7QYr4gbndrZbVzfgCW4pcmP9NbaktzDdi5NjDnz IwvIPoHWKyR2a63tVBILUWL0eHJN6RCS+z0oHH/mccSguGfYHnXAOXZJyh/C8zT7+QB7 MsYvFHtdXgM832LVZFp4KwfSAfQD8NM8nViW+xDWc/0+rC5hAFPJtxX59GDdgbj7fZl5 W9+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:lines:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=dPMGiolFlQ5u+GwkYTG5Cx+92gtnEvoMM51dFwWsV3o=; fh=D1V7xh7f0JVXkR1LGiiuCti+TIsfXrSHXDxzK1xvslg=; b=vsbwuF/uVBP0E9bqrcaZ12Gd3umsFmYSfYUcTqY01nPYv8HbBYxdLl/FwxgAdTOcwr YZd9dLRkit7e9ug4eJErJ2E830MBhKbx7ufvuAkc6iEY6elaeaRdp/cRO68S8dUU9s49 Swmf3jbMMAT4aai3qFyZCmfY8WhlVfFSGqODqYUlh4F0reXuoMbIlAdreZWZFHktUhBz anOpWqc64F1XS/NAa3cSTMDXhDIFj/KYmVEtPx6Ufj6boieiIOqFumgsho7EGavr0x+D ab6nAnDVxG8XoWdZy1RnOpDlpJJmj0frH+P9sI6jlAuur1HxZTL3bOL3597BmUBb33yY OMMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uPKWiP1S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id o4-20020a170902d4c400b001c73f81b24asi4151160plg.521.2023.10.06.07.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 07:31:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uPKWiP1S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1C51680253BE; Fri, 6 Oct 2023 07:31:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232256AbjJFOa5 (ORCPT + 18 others); Fri, 6 Oct 2023 10:30:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232502AbjJFOaz (ORCPT ); Fri, 6 Oct 2023 10:30:55 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 604C4D6 for ; Fri, 6 Oct 2023 07:30:54 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95CBAC433C8; Fri, 6 Oct 2023 14:30:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1696602654; bh=2fhphZG6bxXgGCz3VDXIQ9daJxLkRB/ZDJs2CpCzMAY=; h=From:To:Cc:Subject:Date:From; b=uPKWiP1SV4F7vTV3NT7BFtFzwcQaeWdCBLCOV7OOb+f4Ej+Zp4DvxjkEFs3IP63q8 f0++zS91i5/o3Zvq5y54lKvmrWDZyTx3CoD/xMGvhFQgPjNYijut7ku4760DFdtZ51 VByWkE+Jjp9fUUi5hCdDr/U9OTOHRuW5jKfh2vm4= From: Greg Kroah-Hartman To: virtualization@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Xie Yongji Subject: [PATCH] vduse: make vduse_class constant Date: Fri, 6 Oct 2023 16:30:44 +0200 Message-ID: <2023100643-tricolor-citizen-6c2d@gregkh> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Lines: 137 X-Developer-Signature: v=1; a=openpgp-sha256; l=4498; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=2fhphZG6bxXgGCz3VDXIQ9daJxLkRB/ZDJs2CpCzMAY=; b=owGbwMvMwCRo6H6F97bub03G02pJDKkKUsKfim/9VthzaaV8576syabXTz60elDWo58ssdto1 tWH81bv74hlYRBkYpAVU2T5so3n6P6KQ4pehranYeawMoEMYeDiFICJ/PvIsGA2Q//D46VTpjgt jDCa/9T47L7VU/MZ5sqvOssbtz3o0NRDOnUHeJXvPpI78AwA X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 06 Oct 2023 07:31:15 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779016863688301576 X-GMAIL-MSGID: 1779016863688301576 Now that the driver core allows for struct class to be in read-only memory, we should make all 'class' structures declared at build time placing them into read-only memory, instead of having to be dynamically allocated at runtime. Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Xuan Zhuo Cc: Xie Yongji Signed-off-by: Greg Kroah-Hartman Reviewed-by: Xie Yongji Acked-by: Jason Wang Acked-by: Michael S. Tsirkin --- drivers/vdpa/vdpa_user/vduse_dev.c | 40 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index df7869537ef1..0ddd4b8abecb 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -134,7 +134,6 @@ static DEFINE_MUTEX(vduse_lock); static DEFINE_IDR(vduse_idr); static dev_t vduse_major; -static struct class *vduse_class; static struct cdev vduse_ctrl_cdev; static struct cdev vduse_cdev; static struct workqueue_struct *vduse_irq_wq; @@ -1528,6 +1527,16 @@ static const struct kobj_type vq_type = { .default_groups = vq_groups, }; +static char *vduse_devnode(const struct device *dev, umode_t *mode) +{ + return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev)); +} + +static const struct class vduse_class = { + .name = "vduse", + .devnode = vduse_devnode, +}; + static void vduse_dev_deinit_vqs(struct vduse_dev *dev) { int i; @@ -1638,7 +1647,7 @@ static int vduse_destroy_dev(char *name) mutex_unlock(&dev->lock); vduse_dev_reset(dev); - device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); + device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); idr_remove(&vduse_idr, dev->minor); kvfree(dev->config); vduse_dev_deinit_vqs(dev); @@ -1805,7 +1814,7 @@ static int vduse_create_dev(struct vduse_dev_config *config, dev->minor = ret; dev->msg_timeout = VDUSE_MSG_DEFAULT_TIMEOUT; - dev->dev = device_create_with_groups(vduse_class, NULL, + dev->dev = device_create_with_groups(&vduse_class, NULL, MKDEV(MAJOR(vduse_major), dev->minor), dev, vduse_dev_groups, "%s", config->name); if (IS_ERR(dev->dev)) { @@ -1821,7 +1830,7 @@ static int vduse_create_dev(struct vduse_dev_config *config, return 0; err_vqs: - device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); + device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); err_dev: idr_remove(&vduse_idr, dev->minor); err_idr: @@ -1934,11 +1943,6 @@ static const struct file_operations vduse_ctrl_fops = { .llseek = noop_llseek, }; -static char *vduse_devnode(const struct device *dev, umode_t *mode) -{ - return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev)); -} - struct vduse_mgmt_dev { struct vdpa_mgmt_dev mgmt_dev; struct device dev; @@ -2082,11 +2086,9 @@ static int vduse_init(void) int ret; struct device *dev; - vduse_class = class_create("vduse"); - if (IS_ERR(vduse_class)) - return PTR_ERR(vduse_class); - - vduse_class->devnode = vduse_devnode; + ret = class_register(&vduse_class); + if (ret) + return ret; ret = alloc_chrdev_region(&vduse_major, 0, VDUSE_DEV_MAX, "vduse"); if (ret) @@ -2099,7 +2101,7 @@ static int vduse_init(void) if (ret) goto err_ctrl_cdev; - dev = device_create(vduse_class, NULL, vduse_major, NULL, "control"); + dev = device_create(&vduse_class, NULL, vduse_major, NULL, "control"); if (IS_ERR(dev)) { ret = PTR_ERR(dev); goto err_device; @@ -2141,13 +2143,13 @@ static int vduse_init(void) err_wq: cdev_del(&vduse_cdev); err_cdev: - device_destroy(vduse_class, vduse_major); + device_destroy(&vduse_class, vduse_major); err_device: cdev_del(&vduse_ctrl_cdev); err_ctrl_cdev: unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX); err_chardev_region: - class_destroy(vduse_class); + class_unregister(&vduse_class); return ret; } module_init(vduse_init); @@ -2159,10 +2161,10 @@ static void vduse_exit(void) destroy_workqueue(vduse_irq_bound_wq); destroy_workqueue(vduse_irq_wq); cdev_del(&vduse_cdev); - device_destroy(vduse_class, vduse_major); + device_destroy(&vduse_class, vduse_major); cdev_del(&vduse_ctrl_cdev); unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX); - class_destroy(vduse_class); + class_unregister(&vduse_class); } module_exit(vduse_exit);