On Wed, 29 Jul 2026, [email protected] wrote:
> From: Shixiong Ou <[email protected]>
>
> 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 <[email protected]>
> ---
>  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

Reply via email to