Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2711017pxj; Mon, 31 May 2021 08:50:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu3aXEGezU886tXZUN4A62GoJji3R9/r/2r4WT6sDg6LcblsHcT7Gc5M0LFI06BV8AIBj1 X-Received: by 2002:aa7:cb84:: with SMTP id r4mr26037384edt.187.1622476213276; Mon, 31 May 2021 08:50:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622476213; cv=none; d=google.com; s=arc-20160816; b=zqsftFyJxp6iXIDWPz0+SFo+MBiEqlavOU15F/sOeAIqZ7fiRuJZBO+CP7gBsgDXZl s8UDtz/nVOpnTXPYbWqrGd08MPPq7SmVvfftyC4vKy9pApSWDBjv79ipUsmPd0xZMFOH 5ZMdkm+keKPp3zwF6T3HbdpFe6KqkD7SN5X02qP+7r5TcFCXlGLtqjesn07TkqgrHlsH 6Mzph3a24dvCiugQEKsWL+0rjyqwGu4vNoGdAhsDjo/izbSgq3wu34xkRIz36y1mGLaE zS0LymVgvagowgZ1pOXAMiyMVVsUo5UkqpE6BYwws4Yrsh3cDMQIrZCsaP4QwbgaBmEZ 5akw== 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=u+DAnc2vD5eI8P4XY2mU4hOruh0D5ZgHJ2OiyXYemhw=; b=TP0dvri8ZNd/+93t4wPWXeVg13NmypjGjsEftCdejjYb9BRxwEbauB0EzeuK6HYRNj nrDVit/Mg/0gGFWTk0cn5esUBebJnbecDUEQIqrA4L+cFOZ5Er7rPcWHRgSbfY8hbCXv NbPYDIjIVPqVU0s29XXjqpf/jnitJK+czfidsCrgne7oxOlslnbaWg0UFqIC+qDlBOGG l8zU9/sSQ/Xbu/GHRAeM7vZ11cvfg6c+X0uXe1Whr5LA8zf5+mQIOc8VWSu9B2gqv3d4 EtBw5oX8Wa8MEsYVjeUO01IMupPuM0yxZZ+jJbHpkeQDyUnY2RgnhPzvZJpo35ShkSAX mSSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nAGzp9q+; 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 z25si6957895edq.402.2021.05.31.08.49.51; Mon, 31 May 2021 08:50:13 -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=nAGzp9q+; 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 S232333AbhEaPu3 (ORCPT + 99 others); Mon, 31 May 2021 11:50:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:54450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232757AbhEaO1U (ORCPT ); Mon, 31 May 2021 10:27:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 61A7B61C1D; Mon, 31 May 2021 13:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468840; bh=Djkmej6t9239FeJByM1Gz+iloEPMHMs4iUz1dVvLAkY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nAGzp9q+udLzvT+Cv6Rc6dwBXP94J+jKeQZNJAgsUQXq1vVfZ+OPIzC6kuVALkx/t 7zas/fG6tRvyYNedCGdJIW36BPc7yWiLtYwwKSiuVkuQxJqm957OphuDWOR3YGKqto /b3bHxLNlqykUtOH7D4k6+fIikbFPd/nQkVxkCbw= 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.4 148/177] net: hso: check for allocation failure in hso_create_bulk_serial_device() Date: Mon, 31 May 2021 15:15:05 +0200 Message-Id: <20210531130653.042459928@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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 8c2c6d7921f4..0436e1661096 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -2619,29 +2619,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