From patchwork Tue Feb 2 11:29:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Klimov X-Patchwork-Id: 8189081 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EED219F1C1 for ; Tue, 2 Feb 2016 11:29:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 11DF120256 for ; Tue, 2 Feb 2016 11:29:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2655320251 for ; Tue, 2 Feb 2016 11:29:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754787AbcBBL3k (ORCPT ); Tue, 2 Feb 2016 06:29:40 -0500 Received: from foss.arm.com ([217.140.101.70]:54746 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754279AbcBBL3a (ORCPT ); Tue, 2 Feb 2016 06:29:30 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7C9413FB; Tue, 2 Feb 2016 03:28:46 -0800 (PST) Received: from e105365-lin.cambridge.arm.com (e105365-lin.cambridge.arm.com [10.1.195.47]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1EB253F4FF; Tue, 2 Feb 2016 03:29:28 -0800 (PST) From: Alexey Klimov To: rjw@rjwysocki.net, linux-acpi@vger.kernel.org Cc: jassisinghbrar@gmail.com, sudeep.holla@arm.com, ashwin.chaugule@linaro.org, pprakash@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND] mailbox: pcc: fix channel calculation in get_pcc_channel() Date: Tue, 2 Feb 2016 11:29:22 +0000 Message-Id: <1454412562-28543-1-git-send-email-alexey.klimov@arm.com> X-Mailer: git-send-email 1.9.1 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes the calculation of pcc_chan for non-zero id. After the compiler ignores the (unsigned long) cast the pcc_mbox_channels pointer is type-cast and then the type-cast offset is added which results in address outside of the range leading to the kernel crashing. We might add braces and make it: pcc_chan = (struct mbox_chan *) ((unsigned long) pcc_mbox_channels + (id * sizeof(*pcc_chan))); but let's go with array approach here and use id as index. Tested on Juno board. Acked-by: Sudeep Holla Acked-by: Ashwin Chaugule Signed-off-by: Alexey Klimov --- drivers/mailbox/pcc.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index 45d85ae..8f779a1 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -81,16 +81,10 @@ static struct mbox_controller pcc_mbox_ctrl = {}; */ static struct mbox_chan *get_pcc_channel(int id) { - struct mbox_chan *pcc_chan; - if (id < 0 || id > pcc_mbox_ctrl.num_chans) return ERR_PTR(-ENOENT); - pcc_chan = (struct mbox_chan *) - (unsigned long) pcc_mbox_channels + - (id * sizeof(*pcc_chan)); - - return pcc_chan; + return &pcc_mbox_channels[id]; } /**