Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2115690iof; Tue, 7 Jun 2022 20:15:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwInAebQcxZmnHZU/L/3ZX7KY/fMeI+e0AmPmolt/2gCban07sA8FbCEv74l0/69W57WJA5 X-Received: by 2002:a17:90b:3e85:b0:1e8:8f2f:bd2f with SMTP id rj5-20020a17090b3e8500b001e88f2fbd2fmr12019708pjb.120.1654658139748; Tue, 07 Jun 2022 20:15:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654658139; cv=none; d=google.com; s=arc-20160816; b=LelkEZ4Gfn9I9073JKZAYKd+xCzLjcWynX3gQIJ19sM+YAEYTdDWdMvoLdJYBh1EXQ opBN0xgPGXAnlKaND7a/CsN8IX2+HSj/E1xA+i8wZy4QjIi/R5CTLcrmd38cpP41xxCH 3nA1oGUjbWbyDkeBTPJ4pebL+FI+6a8oWP2MFtrPe0t9cY16Tjk890SX09QgXtXmVsO6 dgoAmQyfbUjgWw7o7dodWOSVUOlgvm6Xlp+n4olNlYAWnnGyITZzHTD3SBWmdcsRN86/ 7wsUkYCaJkX6VpsLrmusfnHe6vVFuZtJcH0RsaZGx/knRh9fvgK8PZa2WDqTKkOWkiFt h/uA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=us4DVu67DvRPBM6mXulpbb3YW5zA4RngvofQU7jImDE=; b=p+90oZGTBtbUV9R5yOrJauXUg+HGhk3lnGsvnzjhGjA9iDtbydryPyItfYY53gr5jr /x2O6Hp6q7i9sD0NTYQwv8Im9p7sXf7glfDKaZYaQ2k8JrkStI6SaVcTA9UXofu8k7wP guCJVxN3w6nCxyHBWFVC5BcSxqyNH/QSwwZtoZZrav7/HfWoaNORVxep0FKPa0GOS/OC PL0mdFLIuE+xWHBsaR2HHUjQoGXQu9f37T+KZNFaYr8d2hNm2VVuy8jPAGzmFTrDfJ/V 4PkUNSBiuYHDu3+AwdgLEzHecV0FPJ67O7coVcI4dCzNOC84rIoII2Cvmmjn6Dgw/cH5 wDkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M1EQ+6DN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d3-20020a63a703000000b003ab2440ce56si25578153pgf.207.2022.06.07.20.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 20:15:39 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M1EQ+6DN; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C971037F648; Tue, 7 Jun 2022 19:18:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383110AbiFGWal (ORCPT + 99 others); Tue, 7 Jun 2022 18:30:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380807AbiFGVQ7 (ORCPT ); Tue, 7 Jun 2022 17:16:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 738981CFF9; Tue, 7 Jun 2022 11:57:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0E57E6176D; Tue, 7 Jun 2022 18:57:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17A41C34115; Tue, 7 Jun 2022 18:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628259; bh=5x9rPzB2VVz92YlALq//O6CF/mu6mIhkuZuW8AeZanY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M1EQ+6DNZDpd6mArIc4lyfhVmCb+KjQra5NnoljBuvL4bGOFjrbE911LJUY4VToSk BJ05b3LKMBv/racdkcCwa68QxlFbshbSWwJs0rJIu2+qRHuP2peMvCTgwh6z7B9mVI huUzLRzmh20t0QeGuhTSk3MVoR10y4CNk0zfZgx8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Javier Martinez Canillas , Sasha Levin Subject: [PATCH 5.18 264/879] drm/ssd130x: Fix rectangle updates Date: Tue, 7 Jun 2022 18:56:22 +0200 Message-Id: <20220607165010.513065628@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Geert Uytterhoeven [ Upstream commit a97e753fd358e23155ae42c61292dfd57eb54c4a ] The rectangle update functions ssd130x_fb_blit_rect() and ssd130x_update_rect() do not behave correctly when x1 != 0 or y1 != 0, or when y1 or y2 are not aligned to display page boundaries. E.g. when used as a text console, only the first line of text is shown on the display. 1. The buffer passed by ssd130x_fb_blit_rect() points to the first byte of monochrome bitmap data, and thus has its origin at (x1, y1), while ssd130x_update_rect() assumes it is at (0, 0). Fix ssd130x_update_rect() by changing the vertical and horizontal loop ranges, and adding the offsets only when needed. 2. In ssd130x_fb_blit_rect(), align y1 and y2 to the display page boundaries before doing the color conversion, so the full page is converted and updated. Remove the correction for an unaligned y1 from ssd130x_update_rect(), and add a check to make sure y1 is aligned. Fixes: a61732e808672cfa ("drm: Add driver for Solomon SSD130x OLED displays") Signed-off-by: Geert Uytterhoeven Acked-by: Javier Martinez Canillas Signed-off-by: Javier Martinez Canillas Link: https://patchwork.freedesktop.org/patch/msgid/20220317081830.1211400-4-geert@linux-m68k.org Signed-off-by: Sasha Levin --- drivers/gpu/drm/solomon/ssd130x.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ssd130x.c index caee851efd57..7c99af4ce9dd 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -355,11 +355,14 @@ static int ssd130x_update_rect(struct ssd130x_device *ssd130x, u8 *buf, unsigned int width = drm_rect_width(rect); unsigned int height = drm_rect_height(rect); unsigned int line_length = DIV_ROUND_UP(width, 8); - unsigned int pages = DIV_ROUND_UP(y % 8 + height, 8); + unsigned int pages = DIV_ROUND_UP(height, 8); + struct drm_device *drm = &ssd130x->drm; u32 array_idx = 0; int ret, i, j, k; u8 *data_array = NULL; + drm_WARN_ONCE(drm, y % 8 != 0, "y must be aligned to screen page\n"); + data_array = kcalloc(width, pages, GFP_KERNEL); if (!data_array) return -ENOMEM; @@ -401,13 +404,13 @@ static int ssd130x_update_rect(struct ssd130x_device *ssd130x, u8 *buf, if (ret < 0) goto out_free; - for (i = y / 8; i < y / 8 + pages; i++) { + for (i = 0; i < pages; i++) { int m = 8; /* Last page may be partial */ - if (8 * (i + 1) > ssd130x->height) + if (8 * (y / 8 + i + 1) > ssd130x->height) m = ssd130x->height % 8; - for (j = x; j < x + width; j++) { + for (j = 0; j < width; j++) { u8 data = 0; for (k = 0; k < m; k++) { @@ -454,6 +457,10 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer *fb, const struct iosys_m int ret = 0; u8 *buf = NULL; + /* Align y to display page boundaries */ + rect->y1 = round_down(rect->y1, 8); + rect->y2 = min_t(unsigned int, round_up(rect->y2, 8), ssd130x->height); + buf = kcalloc(fb->width, fb->height, GFP_KERNEL); if (!buf) return -ENOMEM; -- 2.35.1