From patchwork Mon Jan 4 14:53:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 356641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F25BC433E6 for ; Mon, 4 Jan 2021 14:54:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C2D72225E for ; Mon, 4 Jan 2021 14:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725889AbhADOxw (ORCPT ); Mon, 4 Jan 2021 09:53:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:50394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbhADOxw (ORCPT ); Mon, 4 Jan 2021 09:53:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8893B2076D; Mon, 4 Jan 2021 14:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609771991; bh=J+3vsxzw9vXTfriidHRxRTH6/fVGpXe4m4jfb5Ltbx4=; h=From:To:Cc:Subject:Date:From; b=MWpaEk6mFeku11oDrBQxQZJJtPsTRy0uGKqjRG14b1Nqc8TJ+FEtR80ofSIjS3UND htXPNxIuZze2KGDFD4cSDzWaNt3ftnJRvuiP2yMHBBBiM6teiQovsIQaDAo2QTKCIh q6cf2AwrCMS1+hc4t1cSjjRs/hDbUQr7yccFatF8TXmql6ozZ+1I4f/40dIFH+hgqe UR3KtmrBk3iB02glQakhz/T88YIt4OCiHvHzA43ceKM1uBZ+78UqYTFWpDzU0uJdxW udVNQH+xNDnOWnM/kfm4krbbkaNvu6JQD4fTFLCZA0wQF+jbT4LVaLtZg0K0F+dYVi xZq6BnveTBWZw== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1kwREL-0000YP-31; Mon, 04 Jan 2021 15:53:09 +0100 From: Johan Hovold To: Pete Zaitcev Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, Dan Carpenter , Johan Hovold , stable@vger.kernel.org Subject: [PATCH] USB: usblp: fix DMA to stack Date: Mon, 4 Jan 2021 15:53:02 +0100 Message-Id: <20210104145302.2087-1-johan@kernel.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Stack-allocated buffers cannot be used for DMA (on all architectures). Replace the HP-channel macro with a helper function that allocates a dedicated transfer buffer so that it can continue to be used with arguments from the stack. Note that the buffer is cleared on allocation as usblp_ctrl_msg() returns success also on short transfers (the buffer is only used for debugging). Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/usb/class/usblp.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c index 67cbd42421be..134dc2005ce9 100644 --- a/drivers/usb/class/usblp.c +++ b/drivers/usb/class/usblp.c @@ -274,8 +274,25 @@ static int usblp_ctrl_msg(struct usblp *usblp, int request, int type, int dir, i #define usblp_reset(usblp)\ usblp_ctrl_msg(usblp, USBLP_REQ_RESET, USB_TYPE_CLASS, USB_DIR_OUT, USB_RECIP_OTHER, 0, NULL, 0) -#define usblp_hp_channel_change_request(usblp, channel, buffer) \ - usblp_ctrl_msg(usblp, USBLP_REQ_HP_CHANNEL_CHANGE_REQUEST, USB_TYPE_VENDOR, USB_DIR_IN, USB_RECIP_INTERFACE, channel, buffer, 1) +static int usblp_hp_channel_change_request(struct usblp *usblp, int channel, u8 *new_channel) +{ + u8 *buf; + int ret; + + buf = kzalloc(1, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ret = usblp_ctrl_msg(usblp, USBLP_REQ_HP_CHANNEL_CHANGE_REQUEST, + USB_TYPE_VENDOR, USB_DIR_IN, USB_RECIP_INTERFACE, + channel, buf, 1); + if (ret == 0) + *new_channel = buf[0]; + + kfree(buf); + + return ret; +} /* * See the description for usblp_select_alts() below for the usage