Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1262566rdb; Sat, 7 Oct 2023 22:29:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQJ6U4Q5vIHhv/6IDsSwXApll8znE2dZX7BzCXr5nh/m+1QXww1DSBC8mwb8dgQNqlwXEd X-Received: by 2002:a05:6358:7e92:b0:13c:ee28:2323 with SMTP id o18-20020a0563587e9200b0013cee282323mr12284444rwn.16.1696742963342; Sat, 07 Oct 2023 22:29:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696742963; cv=none; d=google.com; s=arc-20160816; b=CGjb/Bdi1YUsFlUyN/S9V6sgiJopOrBNR/Tq8GeGIN8PUa1NV4IjreuXbrDjcabktn sFF2KLNtQhovYFfzwr2eod46Os43xcxyjQTQEs5q+MyQHoZi7pKh1Z7RY+QJAhBIRPTl fzw5eL/xto8uIAJAn1WC9JniA8YC1M7KVQNo91B23V2wcU8iAtGVFYk4ukV127ImmQBk 0gunUyIeiZCMYO/rM8GHzgreD9m1KvYwCCo/7acEDIlEJccmvkHFdOCim9C0ZD7qE2vL PBbmHFTWK3qptt1IpbBpNE9kDX9nhGLJqe4cNkIkSgrBy604DSlylPirRzWeYiAIFB6C BQiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=QpwgwXaEWYaaFsSNTMyBQD+39EpH2AOMJtj5zGk8lYE=; fh=KZR7RsP+pqpS0Cx/lyO/CgecEdstrS2dwSiQu2dIncg=; b=Vs0zFtKpMacr1+TOROSNHL5fisuBp3u4kfPFSTRJe8KzOPE1h+mqb0Qz0q+q8/LS77 D3XtqoVqm9Noy6WkknOhMqOmsauK05M+FKVyY0HsL/gjeyg/6GoAitdhtTqERCHU/n7E 7HYo6yNgf2BRq86Qc9u152mHhcSOhemTTlLuVhW7lB7G30Uxoz3h3YGB58AY7UHCUWzK Zcs8SIaCftS8tlNd8seS+n88uXVfnMTi9Ayh59Ls7FWXrUbj414avPIyPLyXswTWlRb2 jYyc8/GU9UZwr331uWeaNXqgWFtrS7hf4AEFAUE/4gmiNenkWNxKWrpfjfF9GjBDQ79F 4CVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UuLGoTaa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id pq8-20020a17090b3d8800b0026d60f1627asi7114791pjb.173.2023.10.07.22.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 22:29:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UuLGoTaa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 68B338051140; Sat, 7 Oct 2023 22:29:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344388AbjJHF3J (ORCPT + 99 others); Sun, 8 Oct 2023 01:29:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344322AbjJHF3I (ORCPT ); Sun, 8 Oct 2023 01:29:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E004BCF for ; Sat, 7 Oct 2023 22:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696742908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QpwgwXaEWYaaFsSNTMyBQD+39EpH2AOMJtj5zGk8lYE=; b=UuLGoTaaPNIrzb9jC7kAKsJfamWK0ZhOqkCjw6oijzsL9oYDKF7N/nO/Gjg2ZsUo98muA8 u0vYRwhc4NB80pB/xna3FEhfTFQ/ayck0ervP+xVSFuiYEVoql0u/0rE0N90qibKwhtYWv s7qIo6l2FWShSycLkX8Iepqd+WIjWtM= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-73IRhNdjNHyyhlUD6vvGBQ-1; Sun, 08 Oct 2023 01:28:26 -0400 X-MC-Unique: 73IRhNdjNHyyhlUD6vvGBQ-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-5039413f4f9so286659e87.1 for ; Sat, 07 Oct 2023 22:28:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696742904; x=1697347704; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QpwgwXaEWYaaFsSNTMyBQD+39EpH2AOMJtj5zGk8lYE=; b=l758IRG8ob4ZqNLEbUwCa7o407JT5hbaWEwgPo7JLh6UzHGWAP8Rl2T3owI9SlfFAl pwO9wB1wTWycvP3gzBkGZmXpmL6DFzBKnKM/UN9YMpXuVThJU1ld8B8j0xczPx2aivvx vF8RfEvQmOQ4yuCGXpGL6XblaVmDSrk5Zt4Gu0bk92F+UDrnjLsQwW0to0azxF8BcOQz qouK/UAachfyVCI0hdnca2WoFbmMtrM+3I5xto8APL6K25k1MaHgCaqn2ZmIsIkHLONt ejdle2JJ+GnYOcg4VDhL38hGWhAlufXj7T48GGjWj3FI0AjptNIB32ckW4IRkeYHkQFP laFg== X-Gm-Message-State: AOJu0YzL+0Dd8rdcu3dT2FEUxfsr5VXTQlDnpRrxgO+3wNOANJzNun6P lbzL4XLVDXY/iP7FyJ9kFNgsUiFuIg/c+5dOZ8e8uvVLJoXYPuZBre3EZtFoMt6LK3ajnk4+M6q QnHPBC3QT3J9bTl5zzfLCWUFkp7+1Zho+Z16dHJkcZp8JEKnJZIY= X-Received: by 2002:a05:6512:ac8:b0:503:1aae:eca0 with SMTP id n8-20020a0565120ac800b005031aaeeca0mr13205996lfu.44.1696742904213; Sat, 07 Oct 2023 22:28:24 -0700 (PDT) X-Received: by 2002:a05:6512:ac8:b0:503:1aae:eca0 with SMTP id n8-20020a0565120ac800b005031aaeeca0mr13205990lfu.44.1696742904022; Sat, 07 Oct 2023 22:28:24 -0700 (PDT) MIME-Version: 1.0 References: <2023100643-tricolor-citizen-6c2d@gregkh> In-Reply-To: <2023100643-tricolor-citizen-6c2d@gregkh> From: Jason Wang Date: Sun, 8 Oct 2023 13:28:13 +0800 Message-ID: Subject: Re: [PATCH] vduse: make vduse_class constant To: Greg Kroah-Hartman Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, "Michael S. Tsirkin" , Xuan Zhuo , Xie Yongji Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 agentk.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 (agentk.vger.email [0.0.0.0]); Sat, 07 Oct 2023 22:29:20 -0700 (PDT) X-Spam-Level: ** On Fri, Oct 6, 2023 at 10:31=E2=80=AFPM Greg Kroah-Hartman wrote: > > 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 Acked-by: Jason Wang Thanks > --- > 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 =3D { > .default_groups =3D 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 =3D { > + .name =3D "vduse", > + .devnode =3D 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 =3D ret; > dev->msg_timeout =3D VDUSE_MSG_DEFAULT_TIMEOUT; > - dev->dev =3D device_create_with_groups(vduse_class, NULL, > + dev->dev =3D 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_fop= s =3D { > .llseek =3D 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 =3D class_create("vduse"); > - if (IS_ERR(vduse_class)) > - return PTR_ERR(vduse_class); > - > - vduse_class->devnode =3D vduse_devnode; > + ret =3D class_register(&vduse_class); > + if (ret) > + return ret; > > ret =3D alloc_chrdev_region(&vduse_major, 0, VDUSE_DEV_MAX, "vdus= e"); > if (ret) > @@ -2099,7 +2101,7 @@ static int vduse_init(void) > if (ret) > goto err_ctrl_cdev; > > - dev =3D device_create(vduse_class, NULL, vduse_major, NULL, "cont= rol"); > + dev =3D device_create(&vduse_class, NULL, vduse_major, NULL, "con= trol"); > if (IS_ERR(dev)) { > ret =3D 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); > > -- > 2.42.0 >