Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp48227pxk; Tue, 15 Sep 2020 17:24:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzu/Mu5kZv2YBqX9Bh3ABnGoKdMpean2B6xk4QXE+AkKsTmHIx0f4Iq3eVYsaGehTSxqSvT X-Received: by 2002:aa7:d88a:: with SMTP id u10mr25250452edq.217.1600215892541; Tue, 15 Sep 2020 17:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600215892; cv=none; d=google.com; s=arc-20160816; b=DIEBuSHwUrX0yzd7I8WmwHWjxkkh//ct8tKrxQlOWoDmUwVhakvdYHcjgHhkrgHUa7 +oh3yaGDuREb2SnfnkfThrjtcxHHA+fSqhYNzSOxVcIVPCVfVNDVcTY+tkujqrF3/yRH 4C5/xOhetH6uTeQ1/4F/33VJZhYuWy0HrGlboDlRuYpJYJ+ZeG2nkfsOSsRExhvc+gI0 AjIgzKArtSC7bAlGS3XvU2jd9Ph5Z7iQDk8U877zX+My1uVZSx1g/74DgPH14DC+ZS02 XawfBvdZGuwocOs5o2mVo2+gdM4xW4Iy2U1KlivAWlUBJeycmf53vvaaHNg9kMmF0JaD 36pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NmnIQZdK2ZTtMdcAmmJivMz6m8RyMVyHPpOaDxw2MMo=; b=stHBIFLyje79VlgF9ODmdYXysl9mkFnABCcNJbH3B8u/9NrMjul61kBZiZmgTaAzpk pKM6fOFw0OI04qFQScDpg2jbyzS/gGtMpclbrakXlrDIud1Ea3wAZBkq73A9OCbtLbRB f2/Fa39CnVgyBSzlbwAYz9r/4YiAfdNFcQPXw0i9Tl0wvhSvrEZfhLzV/nQCnzwbfn// Hx3NW/7jR6gNfypw7aLIR78fXGwUsyeTrRfZK+5pyCiYO7nHDJ/0eJqBJzp/F5kQ0tp0 GH2jbd3DSegfYPqPo0wo/dcOT1YY1fbWnqdnNbbNurjRxlP3WW9Q24u6JI1gXxzKeBa7 MxUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zRbaQ1cV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf25si10820780ejb.67.2020.09.15.17.24.30; Tue, 15 Sep 2020 17:24:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zRbaQ1cV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727521AbgIPAXm (ORCPT + 99 others); Tue, 15 Sep 2020 20:23:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:60812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbgIOOU6 (ORCPT ); Tue, 15 Sep 2020 10:20:58 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0B22B22249; Tue, 15 Sep 2020 14:16:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600179417; bh=6ttQ1q99cwkgnU2fv5srLVz3lazMI9eFX5Ivf1tdbFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zRbaQ1cVJ7Oy7DIeX7NvAbJcVgUwizRVxSTfouohbEnb/dsqqB5Dg9xWlrH3cGGvI tJ/N7XLqPwhOOmN8t5AQDOnQh1SFqSv84vAn51v9Sy5Kc13J00oj5UXsRU5uV325df +OO+OIoPbTyEal9kF4DOg5a+2ZMRWVDvWkE05VoQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Jonathan Cameron , Andy Shevchenko , Stable@vger.kernel.org Subject: [PATCH 4.19 51/78] iio: accel: kxsd9: Fix alignment of local buffer. Date: Tue, 15 Sep 2020 16:13:16 +0200 Message-Id: <20200915140636.130895016@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200915140633.552502750@linuxfoundation.org> References: <20200915140633.552502750@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Cameron commit 95ad67577de4ea08eb8e441394e698aa4addcc0b upstream. iio_push_to_buffers_with_timestamp assumes 8 byte alignment which is not guaranteed by an array of smaller elements. Note that whilst in this particular case the alignment forcing of the ts element is not strictly necessary it acts as good documentation. Doing this where not necessary should cut down on the number of cut and paste introduced errors elsewhere. Fixes: 0427a106a98a ("iio: accel: kxsd9: Add triggered buffer handling") Reported-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Cc: Signed-off-by: Greg Kroah-Hartman --- drivers/iio/accel/kxsd9.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) --- a/drivers/iio/accel/kxsd9.c +++ b/drivers/iio/accel/kxsd9.c @@ -212,14 +212,20 @@ static irqreturn_t kxsd9_trigger_handler const struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct kxsd9_state *st = iio_priv(indio_dev); + /* + * Ensure correct positioning and alignment of timestamp. + * No need to zero initialize as all elements written. + */ + struct { + __be16 chan[4]; + s64 ts __aligned(8); + } hw_values; int ret; - /* 4 * 16bit values AND timestamp */ - __be16 hw_values[8]; ret = regmap_bulk_read(st->map, KXSD9_REG_X, - &hw_values, - 8); + hw_values.chan, + sizeof(hw_values.chan)); if (ret) { dev_err(st->dev, "error reading data\n"); @@ -227,7 +233,7 @@ static irqreturn_t kxsd9_trigger_handler } iio_push_to_buffers_with_timestamp(indio_dev, - hw_values, + &hw_values, iio_get_time_ns(indio_dev)); iio_trigger_notify_done(indio_dev->trig);