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 v2] drm/log: Fix division by zero when scale module parameter is 0
Date: Wed, 29 Jul 2026 15:01:34 +0300 [thread overview]
Message-ID: <e9da715ceabaa1dea51ee8bd90aef2ca7409dd0d@intel.com> (raw)
In-Reply-To: <20260729105840.865696-1-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.
>
> Introduce a drm_log_scale() helper that returns scale ?: 1, and use it
> at all read sites. This avoids a race that a setter-based clamp would
> have between param_set_uint() and the subsequent check, where another
> CPU could observe scale == 0.
>
> Signed-off-by: Shixiong Ou <oushixiong@kylinos.cn>
> ---
> v1->v2:
> Introduce a drm_log_scale() helper.
>
> drivers/gpu/drm/clients/drm_log.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/clients/drm_log.c b/drivers/gpu/drm/clients/drm_log.c
> index 294b3be1a6b3..9522c1344123 100644
> --- a/drivers/gpu/drm/clients/drm_log.c
> +++ b/drivers/gpu/drm/clients/drm_log.c
> @@ -29,6 +29,11 @@ static unsigned int scale = 1;
> module_param(scale, uint, 0444);
> MODULE_PARM_DESC(scale, "Integer scaling factor for drm_log, default is 1");
>
> +static inline unsigned int drm_log_scale(void)
Please don't use "inline" in .c files. The compiler will know better
what to do.
BR,
Jani.
> +{
> + return scale ?: 1;
> +}
> +
> /**
> * DOC: overview
> *
> @@ -76,13 +81,13 @@ static void drm_log_blit(struct iosys_map *dst, unsigned int dst_pitch,
> {
> switch (px_width) {
> case 2:
> - drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, scale, color);
> + drm_draw_blit16(dst, dst_pitch, src, src_pitch, height, width, drm_log_scale(), color);
> break;
> case 3:
> - drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, scale, color);
> + drm_draw_blit24(dst, dst_pitch, src, src_pitch, height, width, drm_log_scale(), color);
> break;
> case 4:
> - drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, scale, color);
> + drm_draw_blit32(dst, dst_pitch, src, src_pitch, height, width, drm_log_scale(), color);
> break;
> default:
> WARN_ONCE(1, "Can't blit with pixel width %d\n", px_width);
> @@ -216,8 +221,8 @@ static int drm_log_setup_modeset(struct drm_client_dev *client,
> return -ENOMEM;
> }
> mode_set->fb = scanout->buffer->fb;
> - scanout->scaled_font_h = scanout->font->height * scale;
> - scanout->scaled_font_w = scanout->font->width * scale;
> + scanout->scaled_font_h = scanout->font->height * drm_log_scale();
> + scanout->scaled_font_w = scanout->font->width * drm_log_scale();
> scanout->rows = height / scanout->scaled_font_h;
> scanout->columns = width / scanout->scaled_font_w;
> scanout->front_color = drm_draw_color_from_xrgb8888(0xffffff, format);
--
Jani Nikula, Intel
next prev parent reply other threads:[~2026-07-29 12:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 10:58 [PATCH v2] drm/log: Fix division by zero when scale module parameter is 0 oushixiong1025
2026-07-29 11:14 ` Shixiong Ou
2026-07-29 12:01 ` Jani Nikula [this message]
2026-07-29 15:00 ` Jocelyn Falempe
2026-07-29 15:16 ` Jani Nikula
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=e9da715ceabaa1dea51ee8bd90aef2ca7409dd0d@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