From patchwork Tue Mar 7 21:50:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 65874 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2685252wrd; Tue, 7 Mar 2023 14:00:42 -0800 (PST) X-Google-Smtp-Source: AK7set+M2ZuWbbS72LvO17esMWWGfdxbFwM7fGJa3d1bu6o2KRa9ZCj/oVJ0fjiKcr3lTAGU0Z/c X-Received: by 2002:a17:906:4c84:b0:8b1:e78f:598b with SMTP id q4-20020a1709064c8400b008b1e78f598bmr16289069eju.50.1678226442019; Tue, 07 Mar 2023 14:00:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678226442; cv=none; d=google.com; s=arc-20160816; b=LOBzDMVrpDI4RBqnnn5awLp+8DhAIn+fxyQaMVwsCYAFWJVvVZKU54krxp6Te94j5N qxNtH2RSJriPVw3fWw7HroZHA2WBr3eV/kgffRMvH0tDCGyl4pu6I/fY6gmaCM+YGHK0 SulzGoFV7RXIaxMr3belhOj5TbyDTxvMGjF7rlP3hI77vUHcJo5lt8SYfVzne8Fg+RML +UnT/ODwJfdtRI13/asJFG8CyQH/IWT5VIhViUY3K9wlcZBIjrJHODeUd5Fk3m/GC/17 YfzOyJTmAtbQjSnC6NiDzN5tVfrQi9DGAYmRQ9R2iQIJX2Rs0A1Hxe/s2B1/pv7Hket8 87rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YF8J1V/HdyW06qHE0PQyU5JTwvkaiAFhMsVbeRAMzxc=; b=yNlS/2YsoHQSX9UZ1Qg4chhErOV7Lu2wIjvA54YdqixEw8gPKw2N5EatRTOZjePSSu Qf62ie19zh3n9zTz9WfI2eZdfkt5nuBuBAWAUghjTrVhPrsoAc18Y44BADatZPAXoikt vjngmvdlRqtogc4XR4uHXXJBPauN5PmxrLnCfFVQyc4/SD2IobrcwmKqgFDoRJhFVdLx ba3YpGAZ2dyb+ATg+qwJ1jfaF6lZDbbA0jZU92l2iXLDkbESshHgp+99VgHM6IN4GCp3 A/mhP7booAuUjndBxVh4vAoGQj7WXit3jQGp2Kf5R4Y/67C1v6MPHvmcLZ08drfkNYsN s85w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EYpqUxU0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ml22-20020a170906cc1600b008e1dd2b8defsi1196178ejb.685.2023.03.07.14.00.08; Tue, 07 Mar 2023 14:00:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EYpqUxU0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230247AbjCGVvy (ORCPT + 99 others); Tue, 7 Mar 2023 16:51:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbjCGVvw (ORCPT ); Tue, 7 Mar 2023 16:51:52 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F417A8C48 for ; Tue, 7 Mar 2023 13:50:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678225845; 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=YF8J1V/HdyW06qHE0PQyU5JTwvkaiAFhMsVbeRAMzxc=; b=EYpqUxU0TuqDv5TqA3HoCfG7UkFvzRDGyyVjCnSYL3/WvSATweSMp3sPwmjqyZpE2jW/jZ LpJDW85tLj0bZe58vuxw46nVCQ3EAChqHn7wi6qmnzufuLtftKGIRd5C29nm4dfxfEaYvf 7Z5ukW9R2t0qFN4rJD0cT8t6gvru5fU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-HaRtYFU_NrCw_3Vfjfw3uQ-1; Tue, 07 Mar 2023 16:50:44 -0500 X-MC-Unique: HaRtYFU_NrCw_3Vfjfw3uQ-1 Received: by mail-wm1-f70.google.com with SMTP id x18-20020a1c7c12000000b003e1e7d3cf9fso26012wmc.3 for ; Tue, 07 Mar 2023 13:50:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678225843; 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=YF8J1V/HdyW06qHE0PQyU5JTwvkaiAFhMsVbeRAMzxc=; b=2kvF5DmuEWr38f4kGfqgYjPqJVaGNsEgLw/mUYyuM834NDxZuJ9ZpQSQRuOz9LZxZ8 8ix7f54gIdr+oUwk+YBx0gtItxO/DOFqWJi5+44yxJKkbsWrZsa++RETxKCNt7FO3cOY nymIIvcYjoIKNbLegzdsVnv5b+5tSSlCpdIO1nOQ23CTA8kSwRYmt5kHU5Rn7i3w36Fd v3HSfUMsn7MYIxACKMMWhwnQIRViZBk2CTTZbIjb2SEgrTnz9703ehaCj4gq7fAGHUyr RpPhm5dDJglI/6SYoBayVwkXAY7x0qc78k7Awv/bgxsPuQNlDFun7gsjrVmjZjSvFPQU Haww== X-Gm-Message-State: AO0yUKWO/G3m6U7QpABwL+gHF/y/dlPRbKf0UiIVOXPmxCy/etsrunpT K0xk5SEAr1vzJAtUH5pX/tOObw+SpXCd6r0/DyDFXrEkZi69PP9nov41dkVT+lRSUQ9zMZ0uF3N h66ps3HO0dTHId7CHkxZqQHRIckTnAQH1TOFSxJEVe2C+Nernh9dkwZg4kBreTizyH0qfJnmSqI QNeBCxaBY= X-Received: by 2002:adf:dc90:0:b0:2c5:4c1f:3c9 with SMTP id r16-20020adfdc90000000b002c54c1f03c9mr9559851wrj.49.1678225843090; Tue, 07 Mar 2023 13:50:43 -0800 (PST) X-Received: by 2002:adf:dc90:0:b0:2c5:4c1f:3c9 with SMTP id r16-20020adfdc90000000b002c54c1f03c9mr9559834wrj.49.1678225842666; Tue, 07 Mar 2023 13:50:42 -0800 (PST) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id j2-20020a5d6042000000b002c70d269b4esm13305988wrt.91.2023.03.07.13.50.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 13:50:42 -0800 (PST) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Arthur Grillo , =?utf-8?q?Ma=C3=ADra_Canal?= , Thomas Zimmermann , Maxime Ripard , Javier Martinez Canillas , Daniel Vetter , David Airlie , David Gow , =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= , dri-devel@lists.freedesktop.org Subject: [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts Date: Tue, 7 Mar 2023 22:50:39 +0100 Message-Id: <20230307215039.346863-1-javierm@redhat.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759747969563520175?= X-GMAIL-MSGID: =?utf-8?q?1759747969563520175?= 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 divide it by 8 to account for formats that have sub-byte pixels. Signed-off-by: Javier Martinez Canillas Reviewed-by: Arthur Grillo Reviewed-by: MaĆ­ra Canal --- Tested by making sure that the following command still succeeds: ./tools/testing/kunit/kunit.py run \ --kunitconfig=drivers/gpu/drm/tests/.kunitconfig Changes in v2: - Drop an unused variable, that was pointed out by the kernel robot. drivers/gpu/drm/tests/drm_format_helper_test.c | 7 +++++-- 1 file changed, 5 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..84b5cc29c8fc 100644 --- a/drivers/gpu/drm/tests/drm_format_helper_test.c +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c @@ -409,12 +409,15 @@ 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; 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); + dst_pitch = DIV_ROUND_UP(drm_rect_width(clip) * bpp, 8); + } return dst_pitch * drm_rect_height(clip); }