Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2679742pxj; Mon, 31 May 2021 08:06:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2On5glWhcM0NQK3H22wFtqICCurRkHfS6lkR321gg403ebs43Z1lyW4JkcLV68WaxOvi6 X-Received: by 2002:a17:907:1c1b:: with SMTP id nc27mr24016147ejc.114.1622473577765; Mon, 31 May 2021 08:06:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622473577; cv=none; d=google.com; s=arc-20160816; b=FNe072xOk7lLGEQKaECp9pAiTnu8qKmGqL+Q9eNL5eqUn+VRuGH4i5Zjgu/jDBAGFC wXtjnXmiJNpKg4bDE9pXjMNHYEI/N/wcp0WZQs+crHAcqo+6gIGoNI4q4kkYXtPQFT4n 1fCmdov24uVixP+P0pcjVflRGPRpE4R9d8aD1PlcT2o0GztU08wEdaLWxmGc0+lNOMin yh6gyJh4ggfGZhChGqlOMESKFc9995GodHH+Kc9Cs6CheQVaJUIb5jEvr+EL/osJDUUi udDB9tSGMLKdrcfnQLYh+52955fFzF9cGR4tvYVcHCJ/UTK+ZA33J8WgyAt4ZGMMVOVs i7MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6SP6MkzEtXczvQa63oNyxkM8iP9kJbmxdQ/5VH1nmc8=; b=DjhLkEzNLXKUzB9dMnHUbeXLtFYPwjAZnSdN57hQBJJ3moiOs4X8PmBI+XVCCvwLsm kolVAKehiWC/UQVncGdZt+Ls0JVKh/DPZQAUeQEBQo8gqUzoYUsd040IUjUuSsyJNknJ CGrgnD/aql04MXfah1JRW9aj2ZTXuo6wZxssmYyDa5fXd6SjyO++Epk92VaJicYer+P8 CZzqVISexYQF3FMNBeBjrqxkeYYrUr3GA8igIo0e+IGAklNSllREFe0E9PxuKsqbVRux I5Q2+sk6A6lBq6QASB7cC7bhuzH46oj+BTIIhbuCsV2GD1xhfbDjvd9yxtFne9NZRuQc 2Pbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G52hF3Gv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hp23si12557341ejc.205.2021.05.31.08.05.55; Mon, 31 May 2021 08:06:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G52hF3Gv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233032AbhEaPDo (ORCPT + 99 others); Mon, 31 May 2021 11:03:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:38128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233343AbhEaOHB (ORCPT ); Mon, 31 May 2021 10:07:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9DC8F6195F; Mon, 31 May 2021 13:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468351; bh=p+y3ddyivja8fgExMZ1DS3GPCxyBmRnb/z1yU/Gr1w0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G52hF3GvbLGVkw46eQJY7ahv/+FameFxfF7a1dR52YiSjbN74jW/OgaNqxmDFFajK T3RBvpnL7k+zERfdgoSobt4R2ygXYKrhGksg5Yd7LxIveSJYqC9D+EsX/y3f3GCT+J GuPRjy4SiP8+Qs+YYeEWnY+hftgmZJC2Og6b3anQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Johan Hovold , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 210/252] net: hso: check for allocation failure in hso_create_bulk_serial_device() Date: Mon, 31 May 2021 15:14:35 +0200 Message-Id: <20210531130705.154655315@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit 31db0dbd72444abe645d90c20ecb84d668f5af5e ] In current kernels, small allocations never actually fail so this patch shouldn't affect runtime. Originally this error handling code written with the idea that if the "serial->tiocmget" allocation failed, then we would continue operating instead of bailing out early. But in later years we added an unchecked dereference on the next line. serial->tiocmget->serial_state_notification = kzalloc(); ^^^^^^^^^^^^^^^^^^ Since these allocations are never going fail in real life, this is mostly a philosophical debate, but I think bailing out early is the correct behavior that the user would want. And generally it's safer to bail as soon an error happens. Fixes: af0de1303c4e ("usb: hso: obey DMA rules in tiocmget") Signed-off-by: Dan Carpenter Reviewed-by: Johan Hovold Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/hso.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c index 01566e4d2003..88f87787833c 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -2618,29 +2618,28 @@ static struct hso_device *hso_create_bulk_serial_device( num_urbs = 2; serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget), GFP_KERNEL); + if (!serial->tiocmget) + goto exit; serial->tiocmget->serial_state_notification = kzalloc(sizeof(struct hso_serial_state_notification), GFP_KERNEL); - /* it isn't going to break our heart if serial->tiocmget - * allocation fails don't bother checking this. - */ - if (serial->tiocmget && serial->tiocmget->serial_state_notification) { - tiocmget = serial->tiocmget; - tiocmget->endp = hso_get_ep(interface, - USB_ENDPOINT_XFER_INT, - USB_DIR_IN); - if (!tiocmget->endp) { - dev_err(&interface->dev, "Failed to find INT IN ep\n"); - goto exit; - } - - tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL); - if (tiocmget->urb) { - mutex_init(&tiocmget->mutex); - init_waitqueue_head(&tiocmget->waitq); - } else - hso_free_tiomget(serial); + if (!serial->tiocmget->serial_state_notification) + goto exit; + tiocmget = serial->tiocmget; + tiocmget->endp = hso_get_ep(interface, + USB_ENDPOINT_XFER_INT, + USB_DIR_IN); + if (!tiocmget->endp) { + dev_err(&interface->dev, "Failed to find INT IN ep\n"); + goto exit; } + + tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL); + if (tiocmget->urb) { + mutex_init(&tiocmget->mutex); + init_waitqueue_head(&tiocmget->waitq); + } else + hso_free_tiomget(serial); } else num_urbs = 1; -- 2.30.2