From patchwork Tue Mar 7 19:34:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 13164655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35DE6C678D5 for ; Tue, 7 Mar 2023 19:35:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 86C6810E142; Tue, 7 Mar 2023 19:35:21 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id A8D3310E142 for ; Tue, 7 Mar 2023 19:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678217718; 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; bh=KYmc83GBs2GOcntamM7m0RX9zUZjNNeykOZSju7+M+k=; b=SmmRW+1aKtTRub5R1du4wLsUmnyZsV6Wf1GmjMxQV9mRd+ugLXkleNZ9gq++n9/Sf5R3h9 MwTs7VAZ0HYUrNmj6WqOscvFwK/AagfMNfX+GzfGhBZZko4edWzCNdWIatxnI5C5v9mt/y ckZe/SZC9Oy+CH+w3TfRvjIb+10yGHw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-PSCkgv_1M9ef-NsUT6uWJQ-1; Tue, 07 Mar 2023 14:35:17 -0500 X-MC-Unique: PSCkgv_1M9ef-NsUT6uWJQ-1 Received: by mail-wm1-f71.google.com with SMTP id l31-20020a05600c1d1f00b003e8626cdd42so5166036wms.3 for ; Tue, 07 Mar 2023 11:35:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678217716; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KYmc83GBs2GOcntamM7m0RX9zUZjNNeykOZSju7+M+k=; b=vk3bVo04+cbD3il/08D38Dxid2Y5ADcTSG0yRDj6umXnclTgYXuQQ+WqkubsSEFkYR td0uoBtWkntum8kLcN57IGXTKpoqHnhto/MszUAxGK1M5cq/BrwBshBhwVssMT+Temwp tkdkZLCVEiwx+8hELdUgQsgqeIIYdJ/6ZdpOwR2w/dJ/Ll2AjKumfmtWAfaY7R2GOVfl NH7RT4PuFPCTSqX6FQ8w+aAFQy8p0kavf7XVi1+NOUQx9nNDM54bcwCshCeU6yf0m7fR 1xrTu9y3pOUQqtoQQ8ANBrDDTyS3jjEliFxWSJ2qT0yy0puHy/23d7EcjqVGsQUQFjrs a1yA== X-Gm-Message-State: AO0yUKWCeZp9jj9MYcLtXuL859Or2p8GOzQhD6OsdhqTnBkKuZeMs8qo /Gts2iwt3iIg9w7YjLTCTytChYeTEzv7neiiAE8Y+zzH4P/wlgjJhWGq5KShLOupH+c8wys3dBQ g9GGegUqA5dwTQiygkJ7Njgfw76zx X-Received: by 2002:a05:600c:468b:b0:3df:fcbd:3159 with SMTP id p11-20020a05600c468b00b003dffcbd3159mr10930177wmo.3.1678217716325; Tue, 07 Mar 2023 11:35:16 -0800 (PST) X-Google-Smtp-Source: AK7set9EF/utzGu8fX4TGyh6OXkCzZGiyskAxyksONYkz/GnN0X7MyJNW1dFFpEng/Xh1ROJ6z3ctw== X-Received: by 2002:a05:600c:468b:b0:3df:fcbd:3159 with SMTP id p11-20020a05600c468b00b003dffcbd3159mr10930163wmo.3.1678217716056; Tue, 07 Mar 2023 11:35:16 -0800 (PST) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id b5-20020a05600c150500b003e91b9a92c9sm13617137wmg.24.2023.03.07.11.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 11:35:15 -0800 (PST) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Subject: [PATCH] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts Date: Tue, 7 Mar 2023 20:34:57 +0100 Message-Id: <20230307193457.331360-1-javierm@redhat.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , Javier Martinez Canillas , dri-devel@lists.freedesktop.org, =?utf-8?q?Ma=C3=ADra_Canal?= , Maxime Ripard , David Gow , =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= , Arthur Grillo Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" There are DRM fourcc formats that have pixels smaller than a byte, but the conversion_buf_size() function assumes that pixels are a multiple of bytes and use the struct drm_format_info .cpp field to calculate the dst_pitch. Instead, calculate it by using the bits per pixel (bpp) and char per pixel (cpp) to account for formats that have sub-byte pixels. Signed-off-by: Javier Martinez Canillas --- Tested by making sure that the following command still succeeds: ./tools/testing/kunit/kunit.py run \ --kunitconfig=drivers/gpu/drm/tests/.kunitconfig drivers/gpu/drm/tests/drm_format_helper_test.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c index 9536829c6e3a..f200347a1db7 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -409,12 +409,16 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch, const struct drm_rect *clip) { const struct drm_format_info *dst_fi = drm_format_info(dst_format); + unsigned int bpp, cpp; if (!dst_fi) return -EINVAL; - if (!dst_pitch) - dst_pitch = drm_rect_width(clip) * dst_fi->cpp[0]; + if (!dst_pitch) { + bpp = drm_format_info_bpp(dst_fi, 0); + cpp = DIV_ROUND_UP(bpp, 8); + dst_pitch = DIV_ROUND_UP(drm_rect_width(clip) * bpp, 8); + } return dst_pitch * drm_rect_height(clip); }