Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3529430pxj; Mon, 24 May 2021 08:44:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMV/8lkcXiVlhc8YCfsW9JulaRpWD+atV1i+v8RmQc+1kY62+lyt6lm/fyJGDU3BGoCknB X-Received: by 2002:a05:6e02:1250:: with SMTP id j16mr16922205ilq.217.1621871093749; Mon, 24 May 2021 08:44:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621871093; cv=none; d=google.com; s=arc-20160816; b=b0TGLlukdUBshD6NNvgKBMjoLRONSC1UVkzQhEjeX2lJw1fbHoNWpidtCgI/2rZQ/g 8y7O1ngKg0mmFm6dlKWrY7bUPhTcFy0aVYyDJTppXeMtz6iQfWjiwqoY/yHORIdBe9Gq I1EFmTCaLGfVQ4fZ9Emyv2lVGoKZ8Vq3N40BBHozB/fqeNS/7YOe7LKi76vV2jpPNgP2 oR5QRWiOaGlaAkBNNMfK/vkHhmaUbw6TSaaUsTqI/JE1otmcS0I3rd2ClzGb/Mr3H5YH 0iZmpbe+cI/IgW9yuhKC+ieg7fJKBiN/efwWlgvkY03uxL9F9f1YAfhEWnRNAipIGM66 wE0w== 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=bu5AXJ78TmHtYS6bgvjY65gTLeyomG2v6ddwNlslmR/1sP18Z6Kghw+r52XAQD52d8 1PnVdoMZy0YqxnONASIU/JZ0+G9Zf5MsY9rlwMx5fP4JXOnr0lhL1pECKMvtiwPd8RhJ yzxh7x4PJG0ESOO1O8u2TTbS0rEr6U/VouGOjD5THaU6IyiMvaDiarJUJajL1F5LAJKe ucROiX9cMeiddQGKfs5vZhAVvQWHZc2eKbY4zocmVO3BRx91ZK//uil5T63BBOZdKvEn mzJ6U1qn7Vv6REmDw217kmeqUodvxU4SNmM9S2Gtz93KJb8B4+8lMLAdNis293uBDMxg Mavg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qk9O6yrm; 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 j13si4339022ilk.14.2021.05.24.08.44.40; Mon, 24 May 2021 08:44:53 -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=qk9O6yrm; 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 S234505AbhEXPoW (ORCPT + 99 others); Mon, 24 May 2021 11:44:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:56260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233706AbhEXPkS (ORCPT ); Mon, 24 May 2021 11:40:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 16B356142D; Mon, 24 May 2021 15:34:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621870449; bh=vRPb5bbdFlXhDT9/MX5I0AwXk6wBI1jLoV7lvKlY5pw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qk9O6yrmt9klpudlRc1uhFDqih98Bgg184NgqaBzplGhw3ORbye6UH569kcUhU9Xs Lqfw3bdaqG5v/c0pWOgxyXRKxxZUplyXdoIf6ym+jzSDb+mcpKLKPXCKRqTeIaPvRC ixVeQEuqefnWRxVTywNm8LFnYsniQIpUgo4gDgGw= 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.14 12/37] rapidio: handle create_workqueue() failure Date: Mon, 24 May 2021 17:25:16 +0200 Message-Id: <20210524152324.615677750@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152324.199089755@linuxfoundation.org> References: <20210524152324.199089755@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;