From: Jani Nikula <jani.nikula@linux.intel.com>
To: oushixiong1025@163.com, Jocelyn Falempe <jfalempe@redhat.com>
Cc: Javier Martinez Canillas <javierm@redhat.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
Shixiong Ou <oushixiong@kylinos.cn>
Subject: Re: [PATCH 2/4] drm/log: Fix division by zero when scale module parameter is 0
Date: Wed, 29 Jul 2026 12:48:47 +0300 [thread overview]
Message-ID: <d4c83a8cdd4612525dd32c3036a2789ab8387d99@intel.com> (raw)
In-Reply-To: <20260729084520.688087-2-oushixiong1025@163.com>
On Wed, 29 Jul 2026, oushixiong1025@163.com wrote:
> From: Shixiong Ou <oushixiong@kylinos.cn>
>
> The scale module parameter can be set to 0 via kernel command line or
> sysfs. When scale is 0, scaled_font_h and scaled_font_w become 0,
> causing a division by zero in the rows/columns calculation.
>
> Add a custom param_ops setter to clamp scale to a minimum of 1 at the
> source, ensuring scale is always valid for all users.
>
> Signed-off-by: Shixiong Ou <oushixiong@kylinos.cn>
> ---
> drivers/gpu/drm/clients/drm_log.c | 22 +++++++++++++++++++++-
> 1 file changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/clients/drm_log.c b/drivers/gpu/drm/clients/drm_log.c
> index 294b3be1a6b3..a04f651e8265 100644
> --- a/drivers/gpu/drm/clients/drm_log.c
> +++ b/drivers/gpu/drm/clients/drm_log.c
> @@ -26,7 +26,27 @@ MODULE_DESCRIPTION("DRM boot logger");
> MODULE_LICENSE("GPL");
>
> static unsigned int scale = 1;
> -module_param(scale, uint, 0444);
> +
> +static int drm_log_scale_set(const char *val, const struct kernel_param *kp)
> +{
> + int ret;
> +
> + ret = param_set_uint(val, kp);
> + if (ret)
> + return ret;
Pedantically, scale may be 0 between param_set_uint() and the check
below, i.e. the fix is racy.
An alternative is to use a function to get the scaling factor, and
having it return scale ?: 1.
BR,
Jani.
> +
> + if (scale < 1)
> + scale = 1;
> +
> + return 0;
> +}
> +
> +static const struct kernel_param_ops drm_log_scale_ops = {
> + .set = drm_log_scale_set,
> + .get = param_get_uint,
> +};
> +
> +module_param_cb(scale, &drm_log_scale_ops, &scale, 0444);
> MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default is 1");
>
> /**
--
Jani Nikula, Intel
next prev parent reply other threads:[~2026-07-29 9:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 8:45 [PATCH 1/4] drm/log: Fix out-of-bounds read on empty message length oushixiong1025
2026-07-29 8:45 ` [PATCH 2/4] drm/log: Fix division by zero when scale module parameter is 0 oushixiong1025
2026-07-29 9:48 ` Jani Nikula [this message]
2026-07-29 15:16 ` [PATCH 1/4] drm/log: Fix out-of-bounds read on empty message length Jocelyn Falempe
2026-08-13 14:06 ` Jocelyn Falempe
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=d4c83a8cdd4612525dd32c3036a2789ab8387d99@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=javierm@redhat.com \
--cc=jfalempe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=oushixiong1025@163.com \
--cc=oushixiong@kylinos.cn \
--cc=simona@ffwll.ch \
--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
all inboxes | Powered by JetHome®