From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753044AbbGHXtR (ORCPT ); Wed, 8 Jul 2015 19:49:17 -0400 Received: from smtprelay0121.hostedemail.com ([216.40.44.121]:35344 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751364AbbGHXtG (ORCPT ); Wed, 8 Jul 2015 19:49:06 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:41:355:379:541:599:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1540:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3352:3622:3865:3867:3870:3871:4321:5007:6261:7903:8603:8957:10004:10400:10848:11026:11232:11473:11658:11914:12043:12438:12517:12519:12740:13069:13311:13357:13894:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: fact55_31f9bbdb45a23 X-Filterd-Recvd-Size: 1908 Message-ID: <1436399342.2682.94.camel@perches.com> Subject: Re: [RESEND 2][PATCH v4] hexdump: fix for non-aligned buffers From: Joe Perches To: Horacio Mijail =?ISO-8859-1?Q?Ant=F3n?= Quiles Cc: Andrew Morton , Andy Shevchenko , David Howells , Vivek Goyal , linux-kernel@vger.kernel.org, trivial@kernel.org Date: Wed, 08 Jul 2015 16:49:02 -0700 In-Reply-To: <20150708234418.GA9541@mija-VirtualBox> References: <20150708234418.GA9541@mija-VirtualBox> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.11-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2015-07-09 at 01:44 +0200, Horacio Mijail Antón Quiles wrote: > An hexdump with a buf not aligned to the groupsize causes > non-naturally-aligned memory accesses. This was causing a kernel panic on > the processor BlackFin BF527, when such an unaligned buffer was fed by the > function ubifs_scanned_corruption in fs/ubifs/scan.c . Seems sensible enough to me. > --- > diff --git a/lib/hexdump.c b/lib/hexdump.c [] > @@ -124,6 +124,11 @@ int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize, > if ((len % groupsize) != 0) /* no mixed size output */ > groupsize = 1; > > + /* fall back to 1-byte groups if buf is not aligned to groupsize */ > + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && > + !IS_ALIGNED((uintptr_t)buf, groupsize)) > + groupsize = 1; > + > ngroups = len / groupsize; > ascii_column = rowsize * 2 + rowsize / groupsize + 1; >