Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3525100pxj; Mon, 24 May 2021 08:38:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzI0Llj8RzD5rp+VI8oNQaWyXgfWJvS31r/yETXsa+7wXtEoiJKkgfjJERO+2zkiq3HkD4N X-Received: by 2002:a05:6402:3098:: with SMTP id de24mr25978144edb.339.1621870724981; Mon, 24 May 2021 08:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621870724; cv=none; d=google.com; s=arc-20160816; b=VyTix7+cL/pCfHS+duG/X0tLs05r6AZ/vmzjX3fKc+rLuCz8Z7H+1YEluPIPOFmwiB Uic5nO2NfLWEzaiN0d/5B2YaWPwc2NtArTOuSjhwa7tZOM//3RtW5+FZK17R6eqahw1j J+dH7Nl0GRqgiiRtsLTUPpPTKhm3QXULxEraeOe/AlJcFoNxoemhgPvyH7sFNIuuqIM3 FR2V+RQ+8SItQI8j18srxkCury38S13KQtfdWNExuFN/5E9ODw5w7Z1xRLbCVmjioX1V 9vzd/VUkaLoLOyNwpzyHqj6brDNsRUN5dbsHtvi1wP6n+VF51dj06cIDe3B56z/K1Awd BKuQ== 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=U35Et3Qb2DA3mER3QaJ6/nB0p8KV8xuGs4w9hGVNU4Y=; b=pKUmcKuIXVoK54Pgwpc46e4gt7NZqfvidBwh9CCgEMGz9evVW6WpdcPUhchy4e/Ck2 ryLpZhDs2HR7xL2zkElKe69x0eVpqIn/OFo5WcqJtNgv8yNUih6eDUFTLcRdnaWJ6Gul BUXTZ1s3Jiwj3Lzf0NqKw5ROAUrKrJODGNR9mEo3XtsuMWcqCQE0v7qq+t5LS/1+Aezd 2aSRN7mdEZKREDhmvs8m8nK7PlKCcl1R9dpj/WjpCrTlUguLOB1gOOatKGktx9rRk3+S VW0yb0oh1OZ9SYf4q6cuvODox+fuUdYxKYDiLEifoF0yZPY8pBCZrSBTd/W/Mx6xr9Kg nf5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="n3N/sdBn"; 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 hq1si12304630ejc.659.2021.05.24.08.38.20; Mon, 24 May 2021 08:38:44 -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="n3N/sdBn"; 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 S233213AbhEXPi3 (ORCPT + 99 others); Mon, 24 May 2021 11:38:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:50522 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233493AbhEXPe4 (ORCPT ); Mon, 24 May 2021 11:34:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6B36E613BF; Mon, 24 May 2021 15:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870335; bh=vRPb5bbdFlXhDT9/MX5I0AwXk6wBI1jLoV7lvKlY5pw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n3N/sdBnILkLgrLZ6IbT4b8mP1xfL9wJJQms5ckn/vF5SHInkFvqsTxaefArLqS82 L2QmcU7XwwdHogqIaynEfsQwfFEwLwxcjiVlHgTs09ufnK+FhGR7CYNRcJVOR0DhUR 9RHd2j2n40DlSBqW/PWs0dcd7kJqgWXBnU7B7IUk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandre Bounine , Matt Porter , Andrew Morton , Linus Torvalds , Anirudh Rayabharam Subject: [PATCH 4.9 11/36] rapidio: handle create_workqueue() failure Date: Mon, 24 May 2021 17:24:56 +0200 Message-Id: <20210524152324.538910839@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152324.158146731@linuxfoundation.org> References: <20210524152324.158146731@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: Anirudh Rayabharam commit 69ce3ae36dcb03cdf416b0862a45369ddbf50fdf upstream. In case create_workqueue() fails, release all resources and return -ENOMEM to caller to avoid potential NULL pointer deref later. Move up the create_workequeue() call to return early and avoid unwinding the call to riocm_rx_fill(). Cc: Alexandre Bounine Cc: Matt Porter Cc: Andrew Morton Cc: Linus Torvalds Cc: stable Signed-off-by: Anirudh Rayabharam Link: https://lore.kernel.org/r/20210503115736.2104747-46-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman --- drivers/rapidio/rio_cm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/rapidio/rio_cm.c +++ b/drivers/rapidio/rio_cm.c @@ -2136,6 +2136,14 @@ static int riocm_add_mport(struct device return -ENODEV; } + cm->rx_wq = create_workqueue(DRV_NAME "/rxq"); + if (!cm->rx_wq) { + rio_release_inb_mbox(mport, cmbox); + rio_release_outb_mbox(mport, cmbox); + kfree(cm); + return -ENOMEM; + } + /* * Allocate and register inbound messaging buffers to be ready * to receive channel and system management requests @@ -2146,7 +2154,6 @@ static int riocm_add_mport(struct device cm->rx_slots = RIOCM_RX_RING_SIZE; mutex_init(&cm->rx_lock); riocm_rx_fill(cm, RIOCM_RX_RING_SIZE); - cm->rx_wq = create_workqueue(DRV_NAME "/rxq"); INIT_WORK(&cm->rx_work, rio_ibmsg_handler); cm->tx_slot = 0;