From patchwork Tue Feb 6 20:08:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 10203957 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4A5D0601A1 for ; Tue, 6 Feb 2018 20:08:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CB5D28702 for ; Tue, 6 Feb 2018 20:08:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EF1028D3B; Tue, 6 Feb 2018 20:08:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38E7F28702 for ; Tue, 6 Feb 2018 20:08:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752488AbeBFUIp (ORCPT ); Tue, 6 Feb 2018 15:08:45 -0500 Received: from eddie.linux-mips.org ([148.251.95.138]:47650 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751574AbeBFUIp (ORCPT ); Tue, 6 Feb 2018 15:08:45 -0500 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23992368AbeBFUIn1YepO (ORCPT ); Tue, 6 Feb 2018 21:08:43 +0100 Date: Tue, 6 Feb 2018 21:08:38 +0100 From: Ladislav Michl To: linux-fbdev@vger.kernel.org Cc: Bartlomiej Zolnierkiewicz , Bernie Thompson Subject: [PATCH 1/2] video: udlfb: Fix unaligned access Message-ID: <20180206200838.GA10897@lenoch> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Driver generates lots of alignment trap exceptions on ARM. Fix that by replacing typecasting of odd addresses with byte shifting and remove uneccessary typecasting. Signed-off-by: Ladislav Michl --- Here's what happens on at91sam9g20 few minutes after boot: $ cat /proc/cpu/alignment User: 0 System: 10747836 (dlfb_render_hline+0x22c/0x2f0 [udlfb]) Skipped: 0 Half: 10747971 Word: 159 DWord: 0 Multi: 0 Each hline transfer causes dozens alignment exceptions and few are in dlfb_parse_vendor_descriptor function. drivers/video/fbdev/udlfb.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c index 452a4207ac1b..45081297efa5 100644 --- a/drivers/video/fbdev/udlfb.c +++ b/drivers/video/fbdev/udlfb.c @@ -441,9 +441,9 @@ static void dlfb_compress_hline( *cmd++ = 0xAF; *cmd++ = 0x6B; - *cmd++ = (uint8_t) ((dev_addr >> 16) & 0xFF); - *cmd++ = (uint8_t) ((dev_addr >> 8) & 0xFF); - *cmd++ = (uint8_t) ((dev_addr) & 0xFF); + *cmd++ = dev_addr >> 16; + *cmd++ = dev_addr >> 8; + *cmd++ = dev_addr; cmd_pixels_count_byte = cmd++; /* we'll know this later */ cmd_pixel_start = pixel; @@ -460,8 +460,8 @@ static void dlfb_compress_hline( while (pixel < cmd_pixel_end) { const uint16_t * const repeating_pixel = pixel; - *(uint16_t *)cmd = cpu_to_be16p(pixel); - cmd += 2; + *cmd++ = *pixel >> 8; + *cmd++ = *pixel; pixel++; if (unlikely((pixel < cmd_pixel_end) && @@ -1531,15 +1531,16 @@ static int dlfb_parse_vendor_descriptor(struct dlfb_data *dlfb, u8 length; u16 key; - key = le16_to_cpu(*((u16 *) desc)); - desc += sizeof(u16); - length = *desc; - desc++; + key = *desc++; + key |= (u16)*desc++ << 8; + length = *desc++; switch (key) { case 0x0200: { /* max_area */ - u32 max_area; - max_area = le32_to_cpu(*((u32 *)desc)); + u32 max_area = *desc++; + max_area |= (u32)*desc++ << 8; + max_area |= (u32)*desc++ << 16; + max_area |= (u32)*desc++ << 24; dev_warn(&intf->dev, "DL chip limited to %d pixel modes\n", max_area);