From patchwork Fri Jan 24 09:28:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 233231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBCE1C32771 for ; Fri, 24 Jan 2020 09:49:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 881B8208C4 for ; Fri, 24 Jan 2020 09:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579859370; bh=LH1EaVdIk72JE/+RVcYWv8MVy7qTI6epHMSt1yww51s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=wH8wNPbm03bOoP+9VdYaV8ekENThjLQdlREh2+Tkhznq68SNtUDstg/bIaZ3tLczP bIFz3//p+wCUsVYTz7IZULLWT4wcl4LQ0mS/H+rltbrwyCwI9PWAj4jGQEjzZOewAt 8mtmX5D7IJX1VewaQpx/2p9kuzqxVQwSJO2VqSqU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387800AbgAXJt0 (ORCPT ); Fri, 24 Jan 2020 04:49:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:49734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387682AbgAXJt0 (ORCPT ); Fri, 24 Jan 2020 04:49:26 -0500 Received: from localhost (unknown [145.15.244.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A65CD218AC; Fri, 24 Jan 2020 09:49:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579859365; bh=LH1EaVdIk72JE/+RVcYWv8MVy7qTI6epHMSt1yww51s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mO7Znr4+g31YiCsdcvAWKPZiUGp0WwyTzP3ElLuGy6ioYbXjQYM/9PtHyrXW/SVWm GZdQRCXvSrHYYNvjGD2d404Ge3VwwLpVeJHnSwDDqhmmVxBq0sUWhVZeux2pDshFTW CS6rVtQOMxHCCeKRUZ9vTEHqGMGBc+e5Jf/4+dpc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Sasha Levin Subject: [PATCH 4.14 088/343] staging: most: cdev: add missing check for cdev_add failure Date: Fri, 24 Jan 2020 10:28:26 +0100 Message-Id: <20200124092931.626178657@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124092919.490687572@linuxfoundation.org> References: <20200124092919.490687572@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Colin Ian King [ Upstream commit 5ae890780e1b4d08f2c0c5d4ea96fc3928fc0ee9 ] Currently the call to cdev_add is missing a check for failure. Fix this by checking for failure and exiting via a new error path that ensures the allocated comp_channel struct is kfree'd. Detected by CoverityScan, CID#1462359 ("Unchecked return value") Fixes: 9bc79bbcd0c5 ("Staging: most: add MOST driver's aim-cdev module") Signed-off-by: Colin Ian King Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/most/aim-cdev/cdev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/staging/most/aim-cdev/cdev.c b/drivers/staging/most/aim-cdev/cdev.c index 1e5cbc893496a..d000b6ff8a7d2 100644 --- a/drivers/staging/most/aim-cdev/cdev.c +++ b/drivers/staging/most/aim-cdev/cdev.c @@ -455,7 +455,9 @@ static int aim_probe(struct most_interface *iface, int channel_id, c->devno = MKDEV(major, current_minor); cdev_init(&c->cdev, &channel_fops); c->cdev.owner = THIS_MODULE; - cdev_add(&c->cdev, c->devno, 1); + retval = cdev_add(&c->cdev, c->devno, 1); + if (retval < 0) + goto err_free_c; c->iface = iface; c->cfg = cfg; c->channel_id = channel_id; @@ -491,6 +493,7 @@ error_create_device: list_del(&c->list); error_alloc_kfifo: cdev_del(&c->cdev); +err_free_c: kfree(c); error_alloc_channel: ida_simple_remove(&minor_id, current_minor);