From patchwork Sun Apr 2 17:58:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 78279 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1857333vqo; Sun, 2 Apr 2023 11:03:51 -0700 (PDT) X-Google-Smtp-Source: AKy350aCN1Q7+76B+43VQUQNGD4Glq81pEDjR2cyOXIYf13qS9s3cdqO+xAB2eRaJFU1wBvZEjBv X-Received: by 2002:a17:903:410c:b0:1a1:f0ce:bb8f with SMTP id r12-20020a170903410c00b001a1f0cebb8fmr26879999pld.65.1680458630745; Sun, 02 Apr 2023 11:03:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680458630; cv=none; d=google.com; s=arc-20160816; b=a+MkRrh+m6PxLVJm1Q0JlAVL2BVs3QhHhgZAeZV57ba28+5k/U9H1zQMs7S6t5lMTh SAXpR2x/aSTFMPpHnbAgppNs1frEoaAPXckvxWc4D45fmGPsZ/niy5Z+AVGPYlrFtFle aTVtAbvDYN3P+yc6HcOCHoFaNpwCxJnTIN9xto5C1v/gAU2QCbYR4t5xWrh+VteJWHSx JMDdwqqUvnVF271YimdiHgZQbM0ZWorqNC6N7u6gOFUg/twVUu9W2Uqp56MQ9lz/8gh/ lXI35i4/L6WonzQ9zW0h6cKVL+SrE4vuh1Gd6bGFH68T8/rXgD+D6pOfqbqSy+5dl8OR SACA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yvwuLf3N6zVM6IrYjQ8DJ3FQt61/GTv1/7b1OKkzkxA=; b=ArLFMtual5bxqesI+zLHVhUs/0AD9ZgUCrag0XOL++Qpvmp4qgRT1IytliN4Q2NRqS lDKB4Lr9X3DMMwlq51dkedRdRC5a+qNvHHMiGlsZ8mNjXSQMGepCOivIRl/viwBqQLOR TwCBltGmOzuYbk+nO2nDI92SnDy2wMy69VNgbd0AtrOe6Xfp1BfaO0+giK4JN+TDnEQm gVIT27XzNmwjxHgtFpO7mMTLJ9PROCytj5eI9VBwd9L/uUq974dlfXtofFwWJcpdtINr AyRAC3aJxNTnzyJXZ+eHc95G4ItwDLZXnhhKlzCSgtTNFtin2MOwXpr6ZbmsARRus47k M/Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rcGT+fPD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s195-20020a632ccc000000b00513233eb86asi6492870pgs.593.2023.04.02.11.03.38; Sun, 02 Apr 2023 11:03:50 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rcGT+fPD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231328AbjDBR7a (ORCPT + 99 others); Sun, 2 Apr 2023 13:59:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231310AbjDBR7Z (ORCPT ); Sun, 2 Apr 2023 13:59:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F111012845 for ; Sun, 2 Apr 2023 10:59:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 33C01612D6 for ; Sun, 2 Apr 2023 17:59:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44B43C433D2; Sun, 2 Apr 2023 17:59:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680458357; bh=leWIQAXQz3QXHiAX/iTqJSpy4ZNlpuecBAdl9KGTU0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rcGT+fPDhJJRkEUFgUkTykT3Go2qmi2Tpjn+UO/WIpsa7NhIcSNZ2WUx1b15ToNJG +cepNiUJwjgf5v7sNQyh5GHSIiqZM7GA1MfEwxeHCit4u2b0YrodSpEr99nrbtLPdD Vwi+wYAxeVk2GyhoZiaZjjbvxIUjSM26OM9/4ltM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: rafael@kernel.org, Greg Kroah-Hartman , Jiri Slaby , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH 5/5] tty: make tty_class a static const structure Date: Sun, 2 Apr 2023 19:58:50 +0200 Message-Id: <2023040250-landowner-unfitted-11f4@gregkh> X-Mailer: git-send-email 2.40.0 In-Reply-To: <2023040244-duffel-pushpin-f738@gregkh> References: <2023040244-duffel-pushpin-f738@gregkh> MIME-Version: 1.0 Lines: 138 X-Developer-Signature: v=1; a=openpgp-sha256; l=5137; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=leWIQAXQz3QXHiAX/iTqJSpy4ZNlpuecBAdl9KGTU0A=; b=owGbwMvMwCRo6H6F97bub03G02pJDCmah6IqND1XreO+xpnhz5ejk/vBRl0uk70zS7Nrr5xJ7 P3MFa0dsSwMgkwMsmKKLF+28RzdX3FI0cvQ9jTMHFYmkCEMXJwCMJF7ZxgWzG9ce+y4pZpbwDSj /dN/Ptf78UE+iGE2605l854j4Vv9Fy8t3Pb5qbV4mtYKAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762088589607702114?= X-GMAIL-MSGID: =?utf-8?q?1762088589607702114?= Now that the driver core allows for struct class to be in read-only memory, move the tty_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: Jiri Slaby Cc: "Ilpo Järvinen" Signed-off-by: Greg Kroah-Hartman Reviewed-by: Jiri Slaby --- Jiri and Ilpo, this is part of the larger driver-core changes to make it possible to move struct class into read-only memory and is used as proof that this all works properly. I'll take it throught the driver-core tree as it shoudn't conflict with any tty.git changes. drivers/tty/pty.c | 2 +- drivers/tty/tty_io.c | 24 +++++++++++------------- drivers/tty/vt/vt.c | 2 +- include/linux/tty.h | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index 07394fdaf522..2b1c8ab99dba 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c @@ -931,7 +931,7 @@ static void __init unix98_pty_init(void) if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) || register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0) panic("Couldn't register /dev/ptmx driver"); - device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx"); + device_create(&tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx"); } #else diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 1382d9050ce8..44e0d53aa0b8 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3070,7 +3070,7 @@ static struct device *tty_get_device(struct tty_struct *tty) { dev_t devt = tty_devnum(tty); - return class_find_device_by_devt(tty_class, devt); + return class_find_device_by_devt(&tty_class, devt); } @@ -3143,8 +3143,6 @@ int tty_put_char(struct tty_struct *tty, unsigned char ch) } EXPORT_SYMBOL_GPL(tty_put_char); -struct class *tty_class; - static int tty_cdev_add(struct tty_driver *driver, dev_t dev, unsigned int index, unsigned int count) { @@ -3239,7 +3237,7 @@ struct device *tty_register_device_attr(struct tty_driver *driver, return ERR_PTR(-ENOMEM); dev->devt = devt; - dev->class = tty_class; + dev->class = &tty_class; dev->parent = device; dev->release = tty_device_create_release; dev_set_name(dev, "%s", name); @@ -3294,8 +3292,7 @@ EXPORT_SYMBOL_GPL(tty_register_device_attr); */ void tty_unregister_device(struct tty_driver *driver, unsigned index) { - device_destroy(tty_class, - MKDEV(driver->major, driver->minor_start) + index); + device_destroy(&tty_class, MKDEV(driver->major, driver->minor_start) + index); if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) { cdev_del(driver->cdevs[index]); driver->cdevs[index] = NULL; @@ -3510,13 +3507,14 @@ static char *tty_devnode(const struct device *dev, umode_t *mode) return NULL; } +const struct class tty_class = { + .name = "tty", + .devnode = tty_devnode, +}; + static int __init tty_class_init(void) { - tty_class = class_create("tty"); - if (IS_ERR(tty_class)) - return PTR_ERR(tty_class); - tty_class->devnode = tty_devnode; - return 0; + return class_register(&tty_class); } postcore_initcall(tty_class_init); @@ -3643,13 +3641,13 @@ int __init tty_init(void) if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) || register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) panic("Couldn't register /dev/tty driver\n"); - device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty"); + device_create(&tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty"); cdev_init(&console_cdev, &console_fops); if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) || register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0) panic("Couldn't register /dev/console driver\n"); - consdev = device_create_with_groups(tty_class, NULL, + consdev = device_create_with_groups(&tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL, cons_dev_groups, "console"); if (IS_ERR(consdev)) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 5496bf4b76ec..02f4b6be8584 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -3539,7 +3539,7 @@ int __init vty_init(const struct file_operations *console_fops) if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) || register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) panic("Couldn't register /dev/tty0 driver\n"); - tty0dev = device_create_with_groups(tty_class, NULL, + tty0dev = device_create_with_groups(&tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, vt_dev_groups, "tty0"); if (IS_ERR(tty0dev)) diff --git a/include/linux/tty.h b/include/linux/tty.h index 093935e97f42..121eb4b0d325 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h @@ -387,7 +387,7 @@ extern struct ktermios tty_std_termios; int vcs_init(void); -extern struct class *tty_class; +extern const struct class tty_class; /** * tty_kref_get - get a tty reference