Received: by 2002:ac8:5491:0:b0:40f:fb00:664b with SMTP id h17csp645862qtq; Thu, 10 Aug 2023 11:31:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5l5ECYKa8qPCWB2YufF1KUMAYe9S6wj664ItK1pC6iIiFSx8LxA1NK0oNg1IPaQQDG3X4 X-Received: by 2002:a05:6a20:42a0:b0:12e:cbce:444a with SMTP id o32-20020a056a2042a000b0012ecbce444amr3774446pzj.37.1691692310537; Thu, 10 Aug 2023 11:31:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691692310; cv=none; d=google.com; s=arc-20160816; b=nrVNL08YyArUkC5SAdeVV6R2wEEcTw1o6yhJNT1FLr3r99O1LMhaTWQVbR8ltelNQn HT8TbXeaQWGRGopMFM3ejf59A2irvYIDae2dy88+06ThHQ2g86ASTpDAcsX6U13migR9 8uXr+l+wCGoOwvvIgLp48DAkcrWTypz6gODUUIojna9sMFs1TCy+g6MKi1uTG+SubH1D OkYKOaiKcUfQhD80w9btynATc83oCitLl7b1PsyFUwAM4U+/gA0yC6H9kXuuOrqRzU2A 0pvzJGhR0z00qcwEtigsRQvTvJWMStqa6l32EevbnJedd8s22e14iu2x1sMUQ7Oo5SQq IFWQ== 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:dkim-signature; bh=qEY0l2hGsYfEvo3xdPe/a1UqZtKuGMfO/1XoHriktLk=; fh=X+t8loNN1gLb+pF5Rk7WNbjlo1LDvoDTRiY5znrYOU4=; b=YoD5dB7YFVVW7x4yArwbiw/ZFEtyyt+oKfWRoTZDywBKhdmRjquvFsjkEgay2DPb8G hm2DgImrzzDw3VAbXqhAMbw7oBOf1C9oBw114yMB4GRzuZdfC1S6iPRb3OkYTVkjPfyX JpIUdM7Am3xVOxc3oFrAF7CLXmWfLerxiVpMwIDJBhjTUHeQggshzImiTFzdN2Qv5gpD KQk5qyetrELdf4tweDb9vHnzeysAKbYAkYrPJR8xagHA71IyYXz2TBewLHkYWF4V3akD qhw+CBHiV2Qfi4eQ6sNNX28Bp9mvoWnMFbGw3mJ4IOcP+CnXDw8lh3ihkiCd1QaT4kyd H+FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=f7+77h6l; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k64-20020a638443000000b00543a6cc74bfsi1985295pgd.634.2023.08.10.11.31.36; Thu, 10 Aug 2023 11:31: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=@gmail.com header.s=20221208 header.b=f7+77h6l; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231739AbjHJRqm (ORCPT + 99 others); Thu, 10 Aug 2023 13:46:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbjHJRqk (ORCPT ); Thu, 10 Aug 2023 13:46:40 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C881A2702; Thu, 10 Aug 2023 10:46:39 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fe1f70a139so2412445e9.0; Thu, 10 Aug 2023 10:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691689598; x=1692294398; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qEY0l2hGsYfEvo3xdPe/a1UqZtKuGMfO/1XoHriktLk=; b=f7+77h6leWAsCCaQSRB/TP3b6cMSzmbUAAVQS2DPELn5DI+WaqWpwB1IrwKZR/fLDL PXyD8Mu6wZqtL+Ga1IztR3z+u/FSayr5rPk+VcGkL0uac3xHy4w4S564Yxh/QFAbb8+0 IIVD1hVpdWgkaaf2hlsSZ2Yf13rRxM1MsToO80JW92rAiyy+dpxezzE3HNmllAf3nUvS yXk5nY1blV08sQIoOjS3SqwTACLQzTRUbaWiv08VdmdnV5WlZZ91k9YtkzszQTP3HOQO UHQt/xh66h4emFzbJCL6gtePFkyM5iwoOPhAfyX2IIm5qZgWVXOyEugu8K+KmCql6+4U klyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691689598; x=1692294398; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qEY0l2hGsYfEvo3xdPe/a1UqZtKuGMfO/1XoHriktLk=; b=OrtE4gDxbYgNwmCnKhNxb74lugIj7xI0Wf8Xb1cWZsgBhIIjgCKay7q/RpVk1j6SNg ow7oefH8zdvzB+d/D9KaOTlq692iHYn4Hz6G/MTht9MrpqlG/MPanF/fHi7bz5sQ5vWi ++ihD83LXJ8p41nwDNpXqt/T3fRxKG9MKkiIgXdMQENYZ4UBOeGK7P+pqG89R5Z3l4k0 JOqfvettM0T8a5r7/y1GwItYsMAVGf82qYNkRFNfoleHPL2/PhswOJY/qBa4cZ1+Bsjz 7OG43Tum0+iVVXrElM4IgtHMtyylXjYdASdELeQoOFl6AbXFpQpoc8yQHCVmaZloekfH Npog== X-Gm-Message-State: AOJu0Yz85FMWpVQBY4PMqgFCaKFQKxDAg8ukXn5eyqQCnNjoyeVfVuw5 0aG3NdnhpXO5oc5EwF7jBrw= X-Received: by 2002:a05:600c:5101:b0:3fb:dde9:1de8 with SMTP id o1-20020a05600c510100b003fbdde91de8mr2787958wms.2.1691689598014; Thu, 10 Aug 2023 10:46:38 -0700 (PDT) Received: from ivan-HLYL-WXX9.. ([141.136.93.153]) by smtp.gmail.com with ESMTPSA id h16-20020a5d6e10000000b003176bd661fasm2793424wrz.116.2023.08.10.10.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 10:46:37 -0700 (PDT) From: Ivan Orlov To: wsa@kernel.org Cc: Ivan Orlov , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH] i2c: dev: make i2c_dev_class a static const structure Date: Thu, 10 Aug 2023 21:46:18 +0400 Message-Id: <20230810174618.7844-1-ivan.orlov0322@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 Now that the driver core allows for struct class to be in read-only memory, move the i2c_dev_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Suggested-by: Greg Kroah-Hartman Signed-off-by: Ivan Orlov --- drivers/i2c/i2c-dev.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index a01b59e3599b..a91201509bc1 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -636,7 +636,10 @@ static const struct file_operations i2cdev_fops = { /* ------------------------------------------------------------------------- */ -static struct class *i2c_dev_class; +static const struct class i2c_dev_class = { + .name = "i2c-dev", + .dev_groups = i2c_groups, +}; static void i2cdev_dev_release(struct device *dev) { @@ -665,7 +668,7 @@ static int i2cdev_attach_adapter(struct device *dev) device_initialize(&i2c_dev->dev); i2c_dev->dev.devt = MKDEV(I2C_MAJOR, adap->nr); - i2c_dev->dev.class = i2c_dev_class; + i2c_dev->dev.class = &i2c_dev_class; i2c_dev->dev.parent = &adap->dev; i2c_dev->dev.release = i2cdev_dev_release; @@ -751,12 +754,9 @@ static int __init i2c_dev_init(void) if (res) goto out; - i2c_dev_class = class_create("i2c-dev"); - if (IS_ERR(i2c_dev_class)) { - res = PTR_ERR(i2c_dev_class); + res = class_register(&i2c_dev_class); + if (res) goto out_unreg_chrdev; - } - i2c_dev_class->dev_groups = i2c_groups; /* Keep track of adapters which will be added or removed later */ res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier); @@ -769,7 +769,7 @@ static int __init i2c_dev_init(void) return 0; out_unreg_class: - class_destroy(i2c_dev_class); + class_unregister(&i2c_dev_class); out_unreg_chrdev: unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS); out: @@ -781,7 +781,7 @@ static void __exit i2c_dev_exit(void) { bus_unregister_notifier(&i2c_bus_type, &i2cdev_notifier); i2c_for_each_dev(NULL, i2c_dev_detach_adapter); - class_destroy(i2c_dev_class); + class_unregister(&i2c_dev_class); unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS); } -- 2.34.1