From patchwork Sun Apr 8 17:21:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiro TSUKADA X-Patchwork-Id: 10328393 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 0B8B960385 for ; Sun, 8 Apr 2018 17:22:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDE7B209CC for ; Sun, 8 Apr 2018 17:22:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E05272889E; Sun, 8 Apr 2018 17:22:33 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 82E1E287BD for ; Sun, 8 Apr 2018 17:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752468AbeDHRWc (ORCPT ); Sun, 8 Apr 2018 13:22:32 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:42564 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752412AbeDHRWb (ORCPT ); Sun, 8 Apr 2018 13:22:31 -0400 Received: by mail-pf0-f194.google.com with SMTP id o16so4310243pfk.9 for ; Sun, 08 Apr 2018 10:22:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iKFbo3np/0eObnS+4HE5aMajjIwxYeyYZ2hEHv3S8iY=; b=rOSQR1twBpf7heIqv+jtLqy2o9XFi+XYVb0mE5KZskdb9Vh3/JZvARuNoy5AV59LgW 8lTrdgI4JIpRylhiGmqTFfKuljlMRusGfis0OqWQ3pJQOA1afzJBOBv13VHRszdVbR/U z4g0gCux0zYcTa8j++CaIHyaExpRmE3W2k0Gz9dT6fDs9CBdRAjewLMX35q6K0IJEHSo ElNffLxcdV/SLMT5cybyFyAFO2iPN8KYBNjh0hm8r52V6xpfXjWeDlKB3z+4CtZgI6nc eEDG03CV4OdfE9NEpgBFzmLQQYSN6nMuBnp06jZcU35Hn9UX7Th+zXMfYOobTv2rAJDV X8+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iKFbo3np/0eObnS+4HE5aMajjIwxYeyYZ2hEHv3S8iY=; b=sOzVGbnWMqR41oov3z701d+ExFojgLuIQuU4kYw0dyoIpmXGy4E6l72wdv+kLuhuWc 7AXDIqSHdPWmN2yXavKurBHTKkZznapBJ0O2xJUsotyue93SA+5QNvePFcKdVEt3a4IR /jHVKD71l60Uv47PG4K2kzh/awcokWq79LRikS2f8HqTXcQwjRQbZIjadBFNLDect0Th rdPy6uX4awTrbDVvDahosKMapX9dxpr1fF6psji5yTvi2HMQOQGAENV0E5BP0Ghn1CUo 8GzYBGzVApL2T2LWxvn3QzbU1vEv+M85LG8fv6YxBB8C9lOa1PF7IsQaxBbyp8FvJ4SD FZnQ== X-Gm-Message-State: AElRT7GXIo16+S2gmiJLgKyfQbKGT5wxVClJxRh1bCz5oNJjOGYTrWF3 NxMjoFuK807PffkeO1TKCGH54g== X-Google-Smtp-Source: AIpwx4+Ts+SPWmuB11eZiFvXLz8tfiGNHKTosUJVHZgIE0fmXu7NRYPHkebmf925kcwhUoV/OKg1ew== X-Received: by 10.99.153.17 with SMTP id d17mr23159268pge.62.1523208151248; Sun, 08 Apr 2018 10:22:31 -0700 (PDT) Received: from localhost.localdomain (softbank219203027033.bbtec.net. [219.203.27.33]) by smtp.googlemail.com with ESMTPSA id j125sm33717026pfg.188.2018.04.08.10.22.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Apr 2018 10:22:30 -0700 (PDT) From: tskd08@gmail.com To: linux-media@vger.kernel.org Cc: mchehab@s-opensource.com, Akihiro Tsukada , crope@iki.fi Subject: [PATCH v5 5/5] dvb-usb-v2/gl861: ensure USB message buffers DMA'able Date: Mon, 9 Apr 2018 02:21:38 +0900 Message-Id: <20180408172138.9974-6-tskd08@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180408172138.9974-1-tskd08@gmail.com> References: <20180408172138.9974-1-tskd08@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Akihiro Tsukada i2c message buf might be on stack. Signed-off-by: Akihiro Tsukada --- Changes since v4: - none drivers/media/usb/dvb-usb-v2/gl861.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/dvb-usb-v2/gl861.c b/drivers/media/usb/dvb-usb-v2/gl861.c index cdd7bfcb883..47b614da807 100644 --- a/drivers/media/usb/dvb-usb-v2/gl861.c +++ b/drivers/media/usb/dvb-usb-v2/gl861.c @@ -22,6 +22,8 @@ static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr, u16 value = addr << (8 + 1); int wo = (rbuf == NULL || rlen == 0); /* write-only */ u8 req, type; + u8 *buf; + int ret; if (wo) { req = GL861_REQ_I2C_WRITE; @@ -44,11 +46,23 @@ static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr, KBUILD_MODNAME, wlen); return -EINVAL; } - + buf = NULL; + if (rlen > 0) { + buf = kmalloc(rlen, GFP_KERNEL); + if (!buf) + return -ENOMEM; + } usleep_range(1000, 2000); /* avoid I2C errors */ - return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type, - value, index, rbuf, rlen, 2000); + ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type, + value, index, buf, rlen, 2000); + if (rlen > 0) { + if (ret > 0) + memcpy(rbuf, buf, rlen); + kfree(buf); + } + + return ret; } /* Friio specific I2C read/write */