From: Shixiong Ou <oushixiong1025@163.com>
To: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Cc: Simona Vetter <simona@ffwll.ch>, Helge Deller <deller@gmx.de>,
Thomas Zimmermann <tzimmermann@suse.de>,
Samuel Thibault <samuel.thibault@ens-lyon.org>,
Zsolt Kajtar <soci@c64.rulez.org>,
linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, Shixiong Ou <oushixiong@kylinos.cn>
Subject: Re: [PATCH 1/2] fbcon: Register sysfs groups through device_add_group
Date: Thu, 13 Mar 2025 20:24:51 +0800 [thread overview]
Message-ID: <f6011b3e-97f1-8ead-b9a8-933a015c59ad@163.com> (raw)
In-Reply-To: <20250312173916-23dd381c-2111-413f-8b90-6bda1faaf3d5@linutronix.de>
在 2025/3/13 00:47, Thomas Weißschuh 写道:
> Hi,
>
> On Tue, Mar 11, 2025 at 07:28:55PM +0800, oushixiong1025@163.com wrote:
>> From: Shixiong Ou <oushixiong@kylinos.cn>
>>
>> Use device_add_group() to simplify creation and removal.
>>
>> Signed-off-by: Shixiong Ou <oushixiong@kylinos.cn>
>> ---
>> drivers/video/fbdev/core/fbcon.c | 48 +++++++++++++++-----------------
>> 1 file changed, 22 insertions(+), 26 deletions(-)
>>
>> diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
>> index 07d127110ca4..51c3e8a5a092 100644
>> --- a/drivers/video/fbdev/core/fbcon.c
>> +++ b/drivers/video/fbdev/core/fbcon.c
>> @@ -3159,7 +3159,7 @@ static const struct consw fb_con = {
>> .con_debug_leave = fbcon_debug_leave,
>> };
>>
>> -static ssize_t store_rotate(struct device *device,
>> +static ssize_t rotate_store(struct device *device,
>> struct device_attribute *attr, const char *buf,
>> size_t count)
>> {
>> @@ -3181,7 +3181,7 @@ static ssize_t store_rotate(struct device *device,
>> return count;
>> }
>>
>> -static ssize_t store_rotate_all(struct device *device,
>> +static ssize_t rotate_all_store(struct device *device,
>> struct device_attribute *attr,const char *buf,
>> size_t count)
>> {
>> @@ -3203,7 +3203,7 @@ static ssize_t store_rotate_all(struct device *device,
>> return count;
>> }
>>
>> -static ssize_t show_rotate(struct device *device,
>> +static ssize_t rotate_show(struct device *device,
>> struct device_attribute *attr,char *buf)
>> {
>> struct fb_info *info;
>> @@ -3222,7 +3222,7 @@ static ssize_t show_rotate(struct device *device,
>> return sysfs_emit(buf, "%d\n", rotate);
>> }
>>
>> -static ssize_t show_cursor_blink(struct device *device,
>> +static ssize_t cursor_blink_show(struct device *device,
>> struct device_attribute *attr, char *buf)
>> {
>> struct fb_info *info;
>> @@ -3247,7 +3247,7 @@ static ssize_t show_cursor_blink(struct device *device,
>> return sysfs_emit(buf, "%d\n", blink);
>> }
>>
>> -static ssize_t store_cursor_blink(struct device *device,
>> +static ssize_t cursor_blink_store(struct device *device,
>> struct device_attribute *attr,
>> const char *buf, size_t count)
>> {
>> @@ -3281,32 +3281,30 @@ static ssize_t store_cursor_blink(struct device *device,
>> return count;
>> }
>>
>> -static struct device_attribute device_attrs[] = {
>> - __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
>> - __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
>> - __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
>> - store_cursor_blink),
>> +static DEVICE_ATTR_RW(rotate);
>> +static DEVICE_ATTR_WO(rotate_all);
>> +static DEVICE_ATTR_RW(cursor_blink);
>> +
>> +static struct attribute *fbcon_device_attrs[] = {
>> + &dev_attr_rotate.attr,
>> + &dev_attr_rotate_all.attr,
>> + &dev_attr_cursor_blink.attr,
>> + NULL,
> No trailing commas after sentinel values.
>
>> +};
>> +
>> +static const struct attribute_group fbcon_device_attr_group = {
>> + .attrs = fbcon_device_attrs,
>> };
>>
>> static int fbcon_init_device(void)
>> {
>> - int i, error = 0;
>> + int ret;
>>
>> fbcon_has_sysfs = 1;
>>
>> - for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
>> - error = device_create_file(fbcon_device, &device_attrs[i]);
>> -
>> - if (error)
>> - break;
>> - }
>> -
>> - if (error) {
>> - while (--i >= 0)
>> - device_remove_file(fbcon_device, &device_attrs[i]);
>> -
>> + ret = device_add_group(fbcon_device, &fbcon_device_attr_group);
>> + if (ret)
>> fbcon_has_sysfs = 0;
>> - }
>>
>> return 0;
>> }
>> @@ -3389,11 +3387,9 @@ void __init fb_console_init(void)
>>
>> static void __exit fbcon_deinit_device(void)
>> {
>> - int i;
>>
>> if (fbcon_has_sysfs) {
>> - for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
>> - device_remove_file(fbcon_device, &device_attrs[i]);
>> + device_remove_group(fb_info->dev, &fbcon_device_attr_group);
> Please at least compile-test your changes before submission.
>
>>
>> fbcon_has_sysfs = 0;
>> }
> All of this can be simplified even more:
>
> * fbcon_deinit_device() can be removed easily, as the attributes are
> automatically removed when the device is destroyed.
> * Using device_create_with_groups() the device core will take complete care of
> the attribute lifecycle, also allowing to remove fbcon_init_device()
Thanks for your advice, I will fix and refactor this code in the next patch.
Thanks and Regards,
Shixiong Ou.
>
> Thomas
prev parent reply other threads:[~2025-03-13 12:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-11 11:28 [PATCH 1/2] fbcon: Register sysfs groups through device_add_group oushixiong1025
2025-03-11 11:28 ` [PATCH 2/2] fbcon: Change return value type to void oushixiong1025
2025-03-12 10:20 ` [PATCH 1/2] fbcon: Register sysfs groups through device_add_group kernel test robot
2025-03-12 16:19 ` kernel test robot
2025-03-12 16:47 ` Thomas Weißschuh
2025-03-13 12:24 ` Shixiong Ou [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f6011b3e-97f1-8ead-b9a8-933a015c59ad@163.com \
--to=oushixiong1025@163.com \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oushixiong@kylinos.cn \
--cc=samuel.thibault@ens-lyon.org \
--cc=simona@ffwll.ch \
--cc=soci@c64.rulez.org \
--cc=thomas.weissschuh@linutronix.de \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox