Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3533260pxj; Mon, 24 May 2021 08:50:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzxWnxBLF6rtIOi4mATarxaYODnHnbsK4GqJ/ur0m6Y6Xl+OsyPjmzQyx+vJlFBuPckN4J X-Received: by 2002:a92:db07:: with SMTP id b7mr15225737iln.282.1621871407530; Mon, 24 May 2021 08:50:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621871407; cv=none; d=google.com; s=arc-20160816; b=b38vFh352d+0Lx94AVEOGS1upkdCoRz9bvhYdeZ2ZJap9oncf3RNldKlcXS2wXshqP 1cmR67mOKSZLE+Gz6dZzYq4ZwlxE7mKtAtg06kObeP1I06PlEbFd/Gy4RgjeRRwvRdcn MwXZQPxkn3QsagvORXm98gLLudmfGsju3zSeFgzEquOI6Ax0D2RCGmkUwF0nLhGyEp3k K0ovNfPVVfE4uqJPtOR3c40fO4MidOmX2agPxACmpqCz2tdqFKgrgBRYT8TtfVvMvIi2 0OlkjDtbKUdjmzL5JwSQiT2TpsRyAESjGL29inja+UN3cxJ+BerW4mXpMV2kAldoJWMi 4gIA== 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=jGfU2r9YuPl7fN2Wsd9KWTYcIdp28y6W5cYdFJlxH5zzYR7ZrCkG8Hf8uwY2w07tlF S8PXAsnWAS15gZPnPuv2KI7xQxl89+So0hXOTWHw3gUZAILNEWG6kzHV29hFshQxmFi1 ScgDZBWXqgMXJiXkcSUDtO7uum23yYcc9FWUaPOzNNdq6mQpkoNkpHXwM3xM125zEKR9 p8sDD74i1HhLtiGdS5JDhlDOfvrjiX6Tz3ix4Jahzzx1mwNAbbwwtKcwmvI5KDq3Kpn/ IBB07OMmROcopNeVq+aTc6ON1yAOIWVezrZryljb+7sDQxVXx64Wh88rPLg35Ow11ERp m4pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2fQW1wfT; 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 j23si14298377ioo.31.2021.05.24.08.49.54; Mon, 24 May 2021 08:50:07 -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=2fQW1wfT; 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 S233674AbhEXPuh (ORCPT + 99 others); Mon, 24 May 2021 11:50:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:58234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234331AbhEXPoG (ORCPT ); Mon, 24 May 2021 11:44:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9FB0D61403; Mon, 24 May 2021 15:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870543; bh=vRPb5bbdFlXhDT9/MX5I0AwXk6wBI1jLoV7lvKlY5pw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2fQW1wfTolvmFvArC7ij5W3D9Sr7QAcyXl64yT+O+6A8NJ91zne+gEycAo5288F2c mjGpe0KqhAAHX5IJ/r5qXzK1EQYWJLXxcU4vwheVcfppUb7hXhlEcKyMK/RHqXHhBx FCl4xGmmyv8NJqeXefRxpA8OtzEVetkhr/6+JW5g= 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.19 20/49] rapidio: handle create_workqueue() failure Date: Mon, 24 May 2021 17:25:31 +0200 Message-Id: <20210524152325.035108781@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152324.382084875@linuxfoundation.org> References: <20210524152324.382084875@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;