From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6B963EC805 for ; Wed, 29 Jul 2026 15:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785337227; cv=none; b=ACOllTdvk3mIUB5LVqa/HntjLrjxLZgoSFXVAN4CW5Up5HLmTzDFWH7iJf31fCxoD5K8qsmxgN/rmu3SseTzEpSrHyD8GEI4r/hCjnC9+84SIB6g2d6M5T7htLmEKWrVZZ7TgGIEpfHmHDS0V5v5SDov3kw7Cb1ExFJVcaGmgNo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785337227; c=relaxed/simple; bh=BAWBml+x2OEWdYCDyluyzAzZ1ifswbsY6j+fB2SDxdo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FO6qTNimk9ncJVjB+BZpumk/EaVwEQ0neKXVBhqZc9mgVwcNLdtGJ1syjcewf4Osdv/dcqrldjjX4c+fwUvSTi/u8u6nswVozzPSToZdoB0ZIKygSsmB0dIIsdONNx1+MEmBBHt80YVoucq+2+RyVKJEKvHi2Mj0uSG5VlBrEBU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=crOkM4if; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=nLcycca9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="crOkM4if"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="nLcycca9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785337224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DPXqgOsUU/0okBVvf36ZOSIn4QoJV6rSpP8eJJD/9jc=; b=crOkM4ifiWTpG/KfmT68ZfWNF1YQUz3rp52f7XBujFq6oCClmjASSlSod4De0yhW9bxdxm MIXLPl03s1g65nYU/+io0kR4h7zb6S8JmAI/J/TKp2YhpnHKmux3fM5mcV455PyeALoz+z YZxIWckVedepyfKnpsO8VwWZ7w5YorU= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-196-4c9KuGyOMqGmEMb0WpwdCg-1; Wed, 29 Jul 2026 11:00:23 -0400 X-MC-Unique: 4c9KuGyOMqGmEMb0WpwdCg-1 X-Mimecast-MFC-AGG-ID: 4c9KuGyOMqGmEMb0WpwdCg_1785337222 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-495569acf8dso7550825e9.1 for ; Wed, 29 Jul 2026 08:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1785337222; x=1785942022; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DPXqgOsUU/0okBVvf36ZOSIn4QoJV6rSpP8eJJD/9jc=; b=nLcycca9jlrCrT4WKqOh0LViIVRzBCHMK2FiuY5iUfGcnP+yDC9cvk0oh92buK17xB rtfxF21h047N5Ag68alixqXkvKwMP2m7Rhr79rdGccX+DMSwEtQJ9ghCu+k3dBcE1trS vB8yhzunozimq2qyBO74Ph5SzNwAVqkML77lvZN9hc1UZ3zJ8vFTYYdD/o7pRbpkG9YI GnQXeFApWNNpLJJl9ztl2j9o4/esatEzeBlNn2JXbAVARFLgdQnT5EJJ4wp77q2Ded37 a8tmzjru0CRnyF6COxfSSMFv2CHF7PaJyCR3PVvUCES5pTX2DXm+BThbH80BAU9+3zQq hUbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785337222; x=1785942022; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DPXqgOsUU/0okBVvf36ZOSIn4QoJV6rSpP8eJJD/9jc=; b=U5DSAsd2mHNm5MHD4F4sadp0IGQvihRKHR6qxJyeDFAurSWpUTPjJ3E++ABmnu2UzB eLJ8RlFdG8LJ9FsLlCVx6LE5iV57azI9r2vDa1GYgTRHaFq5Mh+Lis2wsmRSfRRGi6QV iUmH80Z10sb8ekg39WTJyEZXEn0lSG7Glrxc1yzJB1nq0mg2NqxkvLRGVS4RO9OkGBE3 6xBv9H4XePOt4fJDmZEBjig1b4SFqhGd8xGukU75e7wG5qw4u0mBdmX4fPFZdI2XW8lV 836fLUKSqy/RKcXleMst2SGX7X72pBiWE5UzagOFe8IEAGdDDG9qkO0Xz2f6wq4c5ewS LWcw== X-Forwarded-Encrypted: i=1; AHgh+RpdMTOiB72SrJjNjDJeN7BMGtCxju0RAKm8PWglFxhRJnTn+cvmuKx+24ZdwwPiD/feA5j7Ao+kved3sv8=@vger.kernel.org X-Gm-Message-State: AOJu0YxktHufaDbo7smwLm9QnjnB7yNt9xH3aTVKiKstnm11u+P+iARH FoghFCRje5rgDqoyllCCmAWX1WOi/em/Dids3jdnwlKT8nJkNo51zWHoyDXFB2EkqDmeeHO3bcO ttBw6T9hJRTpHO5AtV3ZH7m88IO/rpdatnefHoJFR6iTeWZt1xQOS6sgXJgfOFLUlQw== X-Gm-Gg: AR+sD13Rtyfda6B1NWevgRKACGzGq1FDpb0KlTMfhDlh7gZ3nu566yLzIa8SGCgXI5G 8/BT2iBcVD5I4IP8JgB3KarjneKBmftNGS6rszm/nfOu7CWzRsLDQp8sm649EKb5n1U4k5tAG4L hhQMIVRcb9duQ7hpdQveMmmCIUCHErVf+cTnUEVqxHIDTgCrA+LfROoAOY5mrcuAabuUXM3Tkoy uuRsEm4teCwfuypynR1k4PmqIZuDJmJAD5B/gbFMAdl47qZ8/q3LHmayf13XReg0jY5byOAXhfU S5m4vK9xAnJnXVqntMs0EWsV7G5nNwNwngZb3D/Fe/v+A8S320209OHSGTGYfgQRbw4VdgFYXKx STsRHAtbd/4/+bgVVgxOzGRj70Mh6rG5EG0i4/kk7pxwjBw== X-Received: by 2002:a05:600c:6986:b0:495:6840:9728 with SMTP id 5b1f17b1804b1-496c659d6e2mr90221515e9.38.1785337221588; Wed, 29 Jul 2026 08:00:21 -0700 (PDT) X-Received: by 2002:a05:600c:6986:b0:495:6840:9728 with SMTP id 5b1f17b1804b1-496c659d6e2mr90220695e9.38.1785337221018; Wed, 29 Jul 2026 08:00:21 -0700 (PDT) Received: from ?IPV6:2a01:e0a:9b4:d000:c3c5:df83:3a33:2c51? ([2a01:e0a:9b4:d000:c3c5:df83:3a33:2c51]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49764d777afsm77073955e9.4.2026.07.29.08.00.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jul 2026 08:00:20 -0700 (PDT) Message-ID: <8012b9ea-a39d-437a-8539-9e4c3836d1bd@redhat.com> Date: Wed, 29 Jul 2026 17:00:12 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] drm/log: Fix division by zero when scale module parameter is 0 To: oushixiong1025@163.com Cc: Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Shixiong Ou References: <20260729105840.865696-1-oushixiong1025@163.com> Content-Language: en-US, fr From: Jocelyn Falempe In-Reply-To: <20260729105840.865696-1-oushixiong1025@163.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 29/07/2026 12:58, oushixiong1025@163.com wrote: > From: Shixiong Ou > > 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. The scale module parameter is read only (that's the meaning of 0444 in module_param()) so it can't be set by sysfs, or change at runtime. So this check can be done only once in drm_log_register(). Best regards, -- Jocelyn > > Signed-off-by: Shixiong Ou > --- > 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) > +{ > + 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);