From patchwork Tue Nov 8 16:24:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 9417721 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 F246660512 for ; Tue, 8 Nov 2016 16:27:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2DB72236A for ; Tue, 8 Nov 2016 16:27:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5108288CA; Tue, 8 Nov 2016 16:27:10 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 65BFC2236A for ; Tue, 8 Nov 2016 16:27:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c49D8-0007hX-TS; Tue, 08 Nov 2016 16:25:22 +0000 Received: from quartz.orcorp.ca ([184.70.90.242]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c49D5-0006wm-9G for linux-arm-kernel@lists.infradead.org; Tue, 08 Nov 2016 16:25:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=JMT17avtQaYCCyYWlBIysiQZklzpKhmwT0hroExy7Hs=; b=vLoQWuTTSuGWRCVhw0StWaSmSz6ZuJQNk4XZPM3wkyiaCUGvg4ayFRUbx2VU9Pewq77TlFr4mvwfQoE+H4WyyY+znoFf83AqzPQKAe78Td6WoCskGoSDpepKru479rj/kttxuUz+PoZU7EdYUO6hbNOxba4WUhWawkBKjdCevEU=; Received: from jgg by quartz.orcorp.ca with local (Exim 4.84_2) (envelope-from ) id 1c49Cd-00005U-SX; Tue, 08 Nov 2016 09:24:51 -0700 Date: Tue, 8 Nov 2016 09:24:51 -0700 From: Jason Gunthorpe To: Matthias Brugger Subject: Re: [PATCH] fpga zynq: Check the bitstream for validity Message-ID: <20161108162451.GA31453@obsidianresearch.com> References: <20161028154740.GC10441@obsidianresearch.com> <5ea0e77e-11c5-b4f7-00a9-9c5425ffac5a@suse.com> <20161028165555.GA17998@obsidianresearch.com> <20161028182308.GB18325@live.com> <20161028202619.GA29625@obsidianresearch.com> <20161028210015.GA19901@live.com> <20161028220546.GA19693@obsidianresearch.com> <20161029000926.GA30169@live.com> <20161108004642.GB32444@obsidianresearch.com> <2e0ed43b-9a3e-48d4-4e8a-60d6f25ca4ee@suse.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <2e0ed43b-9a3e-48d4-4e8a-60d6f25ca4ee@suse.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161108_082519_501830_A4B40C87 X-CRM114-Status: GOOD ( 13.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alan Tull , Moritz Fischer , Michal Simek , S??ren Brinkmann , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Nov 08, 2016 at 10:59:43AM +0100, Matthias Brugger wrote: > > /* don't globally reset PL if we're doing partial reconfig */ > > if (!(flags & FPGA_MGR_PARTIAL_RECONFIG)) { > >+ if (!zynq_fpga_has_sync(buf, count)) { > > Maybe we should add an error message here to let the user know what went > wrong, as I think this error path could easily be hit by an user. Sure, happy with this wording: diff --git a/drivers/fpga/zynq-fpga.c b/drivers/fpga/zynq-fpga.c index de475a6a1882..2f3da4c6e2e6 100644 --- a/drivers/fpga/zynq-fpga.c +++ b/drivers/fpga/zynq-fpga.c @@ -181,7 +181,7 @@ static irqreturn_t zynq_fpga_isr(int irq, void *data) */ static bool zynq_fpga_has_sync(const char *buf, size_t count) { - for (; count > 4; buf += 4, --count) + for (; count > 4; buf += 4, count -= 4) if (buf[0] == 0x66 && buf[1] == 0x55 && buf[2] == 0x99 && buf[3] == 0xaa) return true; @@ -200,8 +200,11 @@ static int zynq_fpga_ops_write_init(struct fpga_manager *mgr, u32 flags, /* The hardware can only DMA multiples of 4 bytes, and we need at * least the sync word and something else to do anything. */ - if (count <= 4 || (count % 4) != 0) + if (count <= 4 || (count % 4) != 0) { + dev_err(priv->dev, + "Invalid bitstream size, must be multiples of 4 bytes"); return -EINVAL; + } err = clk_enable(priv->clk); if (err) @@ -210,6 +213,8 @@ static int zynq_fpga_ops_write_init(struct fpga_manager *mgr, u32 flags, /* don't globally reset PL if we're doing partial reconfig */ if (!(flags & FPGA_MGR_PARTIAL_RECONFIG)) { if (!zynq_fpga_has_sync(buf, count)) { + dev_err(priv->dev, + "Invalid bitstream, could not find a sync word. Bitstream must be a byte swaped .bin file"); err = -EINVAL; goto out_err; }