From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Luo Qiu <luoqiu@kylinsec.com.cn>
Cc: Jianmin Lv <lvjianmin@loongson.cn>,
Huacai Chen <chenhuacai@kernel.org>, Yao Zi <ziyao@disroot.org>,
"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
Zixing Liu <liushuyu@aosc.io>,
loongarch@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] platform/loongarch: laptop: Fix backlight device lifetime on unload
Date: Mon, 23 Nov 2026 12:15:56 +0200 [thread overview]
Message-ID: <awQSXIASqC_MdC5u@ashevche-desk.local> (raw)
In-Reply-To: <9F3855F1130E2878+20261121131820.6759-1-luoqiu@kylinsec.com.cn>
On Sat, Nov 21, 2026 at 09:18:20PM +0800, Luo Qiu wrote:
> The driver registers a platform backlight device during module init but
> discards the returned pointer. Consequently, the device is never
> unregistered when the module is removed, leaving its ops callbacks
> pointing into freed module text. After module removal, reading the
> backlight's actual_brightness attribute can call the stale callback and
> crash the kernel. Registration failures are also silently ignored.
>
> Store the returned pointer, use it for resume, and unregister it on
> module exit. Check and report backlight registration failures.
...
> static int loongson_hotkey_resume(struct device *dev)
> {
> int status = 0;
> struct key_entry ke;
> - struct backlight_device *bd;
>
> - bd = backlight_device_get_by_type(BACKLIGHT_PLATFORM);
> - if (bd) {
> - loongson_laptop_backlight_update(bd) ?
> + if (backlight_dev) {
> + loongson_laptop_backlight_update(backlight_dev) ?
> pr_warn("Loongson_backlight: resume brightness failed") :
> - pr_info("Loongson_backlight: resume brightness %d\n", bd->props.brightness);
> + pr_info("Loongson_backlight: resume brightness %d\n",
> + backlight_dev->props.brightness);
Indentation is broken here.
> }
...
> static int laptop_backlight_register(void)
> {
> int status = 0, ret;
> struct backlight_properties props;
> + struct backlight_device *bd;
>
> memset(&props, 0, sizeof(props));
> props.power = BACKLIGHT_POWER_ON;
> props.type = BACKLIGHT_PLATFORM;
>
> - backlight_device_register("loongson_laptop",
> + bd = backlight_device_register("loongson_laptop",
> NULL, NULL, &backlight_laptop_ops, &props);
...and here.
> + if (IS_ERR(bd))
> + return PTR_ERR(bd);
>
> + backlight_dev = bd;
>
> return 0;
> }
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-23 10:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 13:18 Luo Qiu
2026-11-23 10:15 ` Andy Shevchenko [this message]
2026-11-23 13:29 ` Luo Qiu
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=awQSXIASqC_MdC5u@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=chenhuacai@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liushuyu@aosc.io \
--cc=loongarch@lists.linux.dev \
--cc=luoqiu@kylinsec.com.cn \
--cc=lvjianmin@loongson.cn \
--cc=rafael.j.wysocki@intel.com \
--cc=ziyao@disroot.org \
/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
all inboxes | Powered by JetHome®