From patchwork Tue Jun 20 18:01:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 13286317 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD8D5EB64D7 for ; Tue, 20 Jun 2023 18:02:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230493AbjFTSCC (ORCPT ); Tue, 20 Jun 2023 14:02:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230326AbjFTSBs (ORCPT ); Tue, 20 Jun 2023 14:01:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17E7812C; Tue, 20 Jun 2023 11:01:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9EB5961344; Tue, 20 Jun 2023 18:01:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0A2FC433C0; Tue, 20 Jun 2023 18:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687284107; bh=Llf/Ned9bWpyUTNIfPeCq9J4fpBpz1vG2VKuVCLRwac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ns+nAnC4eMK5h5ZIz6RjMrmSOWY80bGcgQooJ1EyFVs3c0vbd8t5a1A3pAExv4IPR 8rbTypyZQ1jMkTayjKdlg/6APp+1IRhEnIMxC2/3LRAxuQYAlMFmplKiQku5B6M1aq KVGtDAkwXoOzFQxIG5Qn0kDGylBn0vmqjppcKtcE= From: Greg Kroah-Hartman To: linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ivan Orlov , Ming Lei , Jens Axboe , Greg Kroah-Hartman Subject: [PATCH 3/4] ublk: make ublk_chr_class a static const structure Date: Tue, 20 Jun 2023 20:01:32 +0200 Message-ID: <20230620180129.645646-7-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230620180129.645646-5-gregkh@linuxfoundation.org> References: <20230620180129.645646-5-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2002; i=gregkh@linuxfoundation.org; h=from:subject; bh=hLzPZz0rmzh84KgaQgMKacJTL3bxIGNFuZVcbSsrVZE=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTX1btfqTzUDKi+PEs1czAv1JPi8IEP6ya+y/OXm/u8 Tm9hTPNOmJZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAiztYM87MOhog8OjxdQP4g v//nzr+WE3wNbzLML72UWhy4llXr0WY19/9N22IT1n24AwA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Ivan Orlov Now that the driver core allows for struct class to be in read-only memory, move the ublk_chr_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Cc: Ming Lei Cc: Jens Axboe Cc: linux-block@vger.kernel.org Suggested-by: Greg Kroah-Hartman Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman --- drivers/block/ublk_drv.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 33d3298a0da1..f25d93365701 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -183,7 +183,9 @@ struct ublk_params_header { }; static dev_t ublk_chr_devt; -static struct class *ublk_chr_class; +static const struct class ublk_chr_class = { + .name = "ublk-char", +}; static DEFINE_IDR(ublk_index_idr); static DEFINE_SPINLOCK(ublk_idr_lock); @@ -1547,7 +1549,7 @@ static int ublk_add_chdev(struct ublk_device *ub) dev->parent = ublk_misc.this_device; dev->devt = MKDEV(MAJOR(ublk_chr_devt), minor); - dev->class = ublk_chr_class; + dev->class = &ublk_chr_class; dev->release = ublk_cdev_rel; device_initialize(dev); @@ -2347,11 +2349,10 @@ static int __init ublk_init(void) if (ret) goto unregister_mis; - ublk_chr_class = class_create("ublk-char"); - if (IS_ERR(ublk_chr_class)) { - ret = PTR_ERR(ublk_chr_class); + ret = class_register(&ublk_chr_class); + if (ret) goto free_chrdev_region; - } + return 0; free_chrdev_region: @@ -2369,7 +2370,7 @@ static void __exit ublk_exit(void) idr_for_each_entry(&ublk_index_idr, ub, id) ublk_remove(ub); - class_destroy(ublk_chr_class); + class_unregister(&ublk_chr_class); misc_deregister(&ublk_misc); idr_destroy(&ublk_index_idr);