Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1271483lqe; Mon, 8 Apr 2024 04:24:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUXZUIyhlELtF8Qc/Zj659Fazi54Dn4ziDDiu2goXGMswYYfslGrupJHwv9/Y5FI0YUYOxV78ArmWXm4azBG/E+Q+8EiSng6mSC9r8UZg== X-Google-Smtp-Source: AGHT+IGqquwyybcrferrsvrvq879xCHoEDgfvcvyAH59VKyKXBZeE8j11zeiQYuazjqFhesRuv00 X-Received: by 2002:a50:f69e:0:b0:56b:8153:54f7 with SMTP id d30-20020a50f69e000000b0056b815354f7mr5788808edn.30.1712575453247; Mon, 08 Apr 2024 04:24:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712575453; cv=pass; d=google.com; s=arc-20160816; b=yEo1w1P1cWd7k0fBdoLUkAlpq4BTG8+d/C+wdZhodENF2OUAHeldq/UFBi4iwGd6a+ 5TSIsPeRy1sCoiUUCHmJ5n6hXAO8bCMYFdLgi1Ggw4po2PeE1UEk+tpnLrGZ7RT18SjN nge+gEQkWF9kcBHS/TX8ru9JGkvEu7uVGhcIDoSa70Hq6vbYNgrG5IN5VmhUBxOc1OWu OzQSbKIwuCoDa/zCIQXUZEYjV0vRAg4SaFgh1qOwNZGU/FZylTedcpN4vkzNoQCeOBxH QaZJDxJwjMn+jkYVv8SOLwJpr4uElWghdMrmVMWlUmyeMl1ElG9RCP/aLo6Q53TguMN9 Phsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=TFlu79+tvZoFZkF5McCiCwr2SQOEryUw2+lzb1vTGI8=; fh=lKCrltZ7cBu0WkGWUuZqtx0M+K+pM9K4u5e4h96Hpx4=; b=ShizjlnUr2/A4eVuVgzCEB0PQBDV7ecaJ4d3S5RZDHgHyMemDE4dRr+sNi+ha1LDzw 7KbVBtBqddN9n8Cn11Y6OOYHV7UcY9qoVCUxhNWOjjC/CjZpAi44tZtg48lnSZ1jNVC8 UnShqjcvs2OWJyVN7vca7Bea+oR6JRgz3odztW16jpn73aZpvFrDFs8QatrKPrsePMLB JKHtB3kIkjyX0+mvUkipDGon9XJVKiQ4a6OZ9RqI8NgLgvMirlDDfq8IklG5y4hOz7wM huFjbYUBR/Rg+n7m2pfY/w0Na3iOK7OPcVu93PdtSc+2Y9zV3g/64S4hO4N1NAGx0p0M UxHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-135262-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135262-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bl14-20020a056402210e00b0056e55ab5e88si1625894edb.591.2024.04.08.04.24.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 04:24:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135262-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-135262-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135262-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CA4EA1F2245B for ; Mon, 8 Apr 2024 11:24:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D586E657CE; Mon, 8 Apr 2024 11:24:02 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37465524DE; Mon, 8 Apr 2024 11:24:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712575442; cv=none; b=Cu1jjIamem7FMMy1r+MLmQIGO53sX0VwuxkQvySbsbYcKONaadTFv9jKQMCvz9FLYcEDGTXbCeZsFBTu5LkcBz9ZFDVi9iRX+MWv8/Cwf5+byJc8VjSwC8cAU4XHz9JGbUg7LR9NZO/zixpi1JnTL9UNT7mmQtgqYIgf3TWBvNE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712575442; c=relaxed/simple; bh=yLlPAbcO7sAzkQT4sLFDTnZOcPu50LAWWkbb3smBAps=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=GpDe4TN/2pZ/QNhrVchKyZsPFFuH8kuUehsG5xYmTrbK69vW8yM2t0rj0FxX4W2mUsu6JZcYyO+tJjfiNCxplR5SvnDCzU1HGsTPjWOeUMEhbPVGy/T4Kc+j5Ii6zblaANacZF2EucsW+d7wIGZMwSVd6+BsT5+4p9viEgfvTUE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5654FC433C7; Mon, 8 Apr 2024 11:24:00 +0000 (UTC) Message-ID: <3a480ef5-f222-4a0d-b236-6587cd276631@xs4all.nl> Date: Mon, 8 Apr 2024 13:23:58 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] media: dvbdev: make dvb_class constant Content-Language: en-US, nl To: "Ricardo B. Marliere" Cc: Mauro Carvalho Chehab , Sean Young , Greg Kroah-Hartman , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240305-class_cleanup-media-v1-0-53e1538973cd@marliere.net> <20240305-class_cleanup-media-v1-1-53e1538973cd@marliere.net> From: Hans Verkuil Autocrypt: addr=hverkuil@xs4all.nl; keydata= xsFNBFQ84W0BEAC7EF1iL4s3tY8cRTVkJT/297h0Hz0ypA+ByVM4CdU9sN6ua/YoFlr9k0K4 BFUlg7JzJoUuRbKxkYb8mmqOe722j7N3HO8+ofnio5cAP5W0WwDpM0kM84BeHU0aPSTsWiGR yw55SOK2JBSq7hueotWLfJLobMWhQii0Zd83hGT9SIt9uHaHjgwmtTH7MSTIiaY6N14nw2Ud C6Uykc1va0Wqqc2ov5ihgk/2k2SKa02ookQI3e79laOrbZl5BOXNKR9LguuOZdX4XYR3Zi6/ BsJ7pVCK9xkiVf8svlEl94IHb+sa1KrlgGv3fn5xgzDw8Z222TfFceDL/2EzUyTdWc4GaPMC E/c1B4UOle6ZHg02+I8tZicjzj5+yffv1lB5A1btG+AmoZrgf0X2O1B96fqgHx8w9PIpVERN YsmkfxvhfP3MO3oHh8UY1OLKdlKamMneCLk2up1Zlli347KMjHAVjBAiy8qOguKF9k7HOjif JCLYTkggrRiEiE1xg4tblBNj8WGyKH+u/hwwwBqCd/Px2HvhAsJQ7DwuuB3vBAp845BJYUU3 06kRihFqbO0vEt4QmcQDcbWINeZ2zX5TK7QQ91ldHdqJn6MhXulPKcM8tCkdD8YNXXKyKq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PVvwSWsRQp2LxFCkwnCXOra gYmkrmv0duG1FStpY+IIQn1TOkuXrciTVfZY1cZD0aVxwlxXBnUNZZNslldvXFtndxR0SFat sflovhDxKyhFwXOP0Rv8H378/+14TaykknRBIKEc0+lcr+EMOSUR5eg4aURb8Gc3Uc7fgQ6q UssTXzHPyj1hAyDpfu8DzAwlh4kKFTodxSsKAjI45SLjadSc94/5Gy8645Y1KgBzBPTH7Q== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 08/04/2024 12:47, Ricardo B. Marliere wrote: > Hi Hans! > > On 8 Apr 11:47, Hans Verkuil wrote: >> On 05/03/2024 14:26, Ricardo B. Marliere wrote: >>> Since commit 43a7206b0963 ("driver core: class: make class_register() take >>> a const *"), the driver core allows for struct class to be in read-only >>> memory, so move the dvb_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: Greg Kroah-Hartman >>> Suggested-by: Greg Kroah-Hartman >>> Signed-off-by: Ricardo B. Marliere >>> --- >>> drivers/media/dvb-core/dvbdev.c | 23 +++++++++++++---------- >>> 1 file changed, 13 insertions(+), 10 deletions(-) >>> >>> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c >>> index 733d0bc4b4cc..dcbf68b00240 100644 >>> --- a/drivers/media/dvb-core/dvbdev.c >>> +++ b/drivers/media/dvb-core/dvbdev.c >>> @@ -78,7 +78,13 @@ static const u8 minor_type[] = { >>> #define MAX_DVB_MINORS (DVB_MAX_ADAPTERS * 64) >>> #endif >>> >>> -static struct class *dvb_class; >>> +static int dvb_uevent(const struct device *dev, struct kobj_uevent_env *env); >>> +static char *dvb_devnode(const struct device *dev, umode_t *mode); >> >> Forward references are typically something you want to avoid. >> >> Looking at the code, I think it makes sense to just move those two functions >> to just before this dvb_class. > > Ack. > >> >>> +static const struct class dvb_class = { >>> + .name = "dvb", >>> + .dev_uevent = dvb_uevent, >>> + .devnode = dvb_devnode, >>> +}; >>> >>> static struct dvb_device *dvb_minors[MAX_DVB_MINORS]; >>> static DECLARE_RWSEM(minor_rwsem); >> >> Also move the dvb_class (+ the two functions) to after this line. I think that's >> a more suitable place for this. > > Ack. > >> >>> @@ -561,7 +567,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev, >>> return ret; >>> } >>> >>> - clsdev = device_create(dvb_class, adap->device, >>> + clsdev = device_create(&dvb_class, adap->device, >>> MKDEV(DVB_MAJOR, minor), >>> dvbdev, "dvb%d.%s%d", adap->num, dnames[type], id); >>> if (IS_ERR(clsdev)) { >>> @@ -600,7 +606,7 @@ void dvb_remove_device(struct dvb_device *dvbdev) >>> >>> dvb_media_device_free(dvbdev); >>> >>> - device_destroy(dvb_class, MKDEV(DVB_MAJOR, dvbdev->minor)); >>> + device_destroy(&dvb_class, MKDEV(DVB_MAJOR, dvbdev->minor)); >>> >>> list_del(&dvbdev->list_head); >>> } >>> @@ -1096,13 +1102,10 @@ static int __init init_dvbdev(void) >>> goto error; >>> } >>> >>> - dvb_class = class_create("dvb"); >>> - if (IS_ERR(dvb_class)) { >>> - retval = PTR_ERR(dvb_class); >>> + retval = class_register(&dvb_class); >>> + if (retval != 0) >> >> This can just be 'if (retval)'. > > But then it would be on a different style than the rest of the function: Ah, I hadn't noticed that. Let's keep it as you proposed then. Regards, Hans > > static int __init init_dvbdev(void) > { > int retval; > dev_t dev = MKDEV(DVB_MAJOR, 0); > > retval = register_chrdev_region(dev, MAX_DVB_MINORS, "DVB"); > if (retval != 0) { > pr_err("dvb-core: unable to get major %d\n", DVB_MAJOR); > return retval; > } > > cdev_init(&dvb_device_cdev, &dvb_device_fops); > retval = cdev_add(&dvb_device_cdev, dev, MAX_DVB_MINORS); > if (retval != 0) { > pr_err("dvb-core: unable register character device\n"); > goto error; > } > > retval = class_register(&dvb_class); > if (retval != 0) > goto error; > > return 0; > > error: > cdev_del(&dvb_device_cdev); > unregister_chrdev_region(dev, MAX_DVB_MINORS); > return retval; > } > > >> >>> goto error; >>> - } >>> - dvb_class->dev_uevent = dvb_uevent; >>> - dvb_class->devnode = dvb_devnode; >>> + >>> return 0; >>> >>> error: >>> @@ -1115,7 +1118,7 @@ static void __exit exit_dvbdev(void) >>> { >>> struct dvbdevfops_node *node, *next; >>> >>> - class_destroy(dvb_class); >>> + class_unregister(&dvb_class); >>> cdev_del(&dvb_device_cdev); >>> unregister_chrdev_region(MKDEV(DVB_MAJOR, 0), MAX_DVB_MINORS); >>> >>> >> >> Regards, >> >> Hans