From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9431BC25B06 for ; Thu, 11 Aug 2022 16:37:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238801AbiHKQhb (ORCPT ); Thu, 11 Aug 2022 12:37:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239190AbiHKQga (ORCPT ); Thu, 11 Aug 2022 12:36:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09633140F5; Thu, 11 Aug 2022 09:11:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7EE006145A; Thu, 11 Aug 2022 16:11:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C7A4C433B5; Thu, 11 Aug 2022 16:11:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660234310; bh=hYfF9x6Llkv5mlZDQyklaZZ77hbqhuh9/NJbJaFW1tA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uhFkDAdx8Xeg3sbU0zC3ybEsPVU7/wCt/+pl7Fmr63u7ZOFSYEF31eN+eWTciEt1M R/VQPSHib/taa0M+QXwxegjPVm4z2ftPJWhptv1WRV0ogCwKWZSSpuJlq4d0H+t6i2 yIo6yjglAxCtNEYmNc5tGC1AphuPdj/7ZQkTNTo3in1/441CuJiwbFLiCW2OfmWSj5 +TtAH+rrAp8k82swZkSctB45t/8ZxrvgpJ/GGUpzaVS4eRC7TjM7662ANT2j+P7Bxd s+zpm5hRPuXQ8IhXQqdC47MBmAhYcyKWGlYtmZS/tkiqDRNlw3Y9RIzuYjM00rmx73 iYkt2q5cmDv6A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Oliver Neukum , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin , crope@iki.fi, linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 03/12] media: airspy: respect the DMA coherency rules Date: Thu, 11 Aug 2022 12:11:29 -0400 Message-Id: <20220811161144.1543598-3-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220811161144.1543598-1-sashal@kernel.org> References: <20220811161144.1543598-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Oliver Neukum [ Upstream commit ca9dc8d06ab64543a6a31adac5003349c5671218 ] If we want to avoid memory corruption on incoherent architectures, buffers for DMA must not reside - on the stack - embedded within other structures Allocate them separately. v2: fix uninitialized return value Signed-off-by: Oliver Neukum Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/airspy/airspy.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/airspy/airspy.c b/drivers/media/usb/airspy/airspy.c index 8251942bcd12..1c549ad60195 100644 --- a/drivers/media/usb/airspy/airspy.c +++ b/drivers/media/usb/airspy/airspy.c @@ -134,7 +134,7 @@ struct airspy { /* USB control message buffer */ #define BUF_SIZE 128 - u8 buf[BUF_SIZE]; + u8 *buf; /* Current configuration */ unsigned int f_adc; @@ -872,6 +872,7 @@ static void airspy_video_release(struct v4l2_device *v) v4l2_ctrl_handler_free(&s->hdl); v4l2_device_unregister(&s->v4l2_dev); + kfree(s->buf); kfree(s); } @@ -979,7 +980,10 @@ static int airspy_probe(struct usb_interface *intf, { struct airspy *s; int ret; - u8 u8tmp, buf[BUF_SIZE]; + u8 u8tmp, *buf; + + buf = NULL; + ret = -ENOMEM; s = kzalloc(sizeof(struct airspy), GFP_KERNEL); if (s == NULL) { @@ -987,6 +991,13 @@ static int airspy_probe(struct usb_interface *intf, return -ENOMEM; } + s->buf = kzalloc(BUF_SIZE, GFP_KERNEL); + if (!s->buf) + goto err_free_mem; + buf = kzalloc(BUF_SIZE, GFP_KERNEL); + if (!buf) + goto err_free_mem; + mutex_init(&s->v4l2_lock); mutex_init(&s->vb_queue_lock); spin_lock_init(&s->queued_bufs_lock); @@ -1082,6 +1093,8 @@ static int airspy_probe(struct usb_interface *intf, v4l2_ctrl_handler_free(&s->hdl); v4l2_device_unregister(&s->v4l2_dev); err_free_mem: + kfree(buf); + kfree(s->buf); kfree(s); return ret; } -- 2.35.1