Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3316494pxf; Mon, 15 Mar 2021 07:02:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLymtGrudAM9tEa/EfRqfSFFVDRALA2QOkKIk809ZL14WMsTuQW9yoeH12PgaSwhREge3K X-Received: by 2002:aa7:c850:: with SMTP id g16mr29680237edt.324.1615816926292; Mon, 15 Mar 2021 07:02:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615816926; cv=none; d=google.com; s=arc-20160816; b=YpOvWWlVNaS7Jmq577ZtnwsTXk4FvbII08jSurl1sALAGRI6Cyl/0OzQ5EcnugF9AW 4jRDYLG1KE5ChOdD9hlC0CXYRRKi5T4NoNZLeWSTnXyx+5hQCQqerzdM8BZ0alPfw4wL U+7dRpqWyne40sTia+v9upT8G90RnXFJcCzAkAszEHKBF+cRRhwj6N+2xQjPEo2e7sf7 09T8NuIr4VP5ytnWKZ4t+1jOzod6G93hpEfZfHy9JTqG44q0boiNGWnuXzF/5o7O1dc2 iRPT2xTFkoDn0lmk0u34Bg2izRskiRrMdhro8GSypDRGVjitvI7epudLnuispyoOu5Go SbPA== 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=58VWcvcNzXluZvNYYq78k7oHAyNGsUImPPcpyLnvOP8=; b=auaSQ/jnoxvdXucnzEzk0FO71lfFIcwWHmR7H7py8KNpcXYncp26MYguCy/Fx8E08Y 4Sxd78YC7B4KD7dlsQvuU7Xwn9GtEeEfuK7WAjh59ie0i1usKrkUyua6T0bGyWRTvwb5 6bt5VyjCXP6tzR5WaEoHZICXlMswmY+nkMQxG38f6ZFZAt62bPPIqJwP8901hgrKJyrH NGFTu3Rn1ijeVIOLpkCPdZ9h25lRo3hYv1mB/xrbUvvophwyPRbZbTjxjjxqM9lXKBA9 BwVbHfAGUu0lPD5/h36ed1YgNHpkR3pGE+hBz/oFCH9W6ceMEioTiMbxlm/w/GBwK0w+ jW7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="kvsmlU/G"; 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 g10si11436351edq.430.2021.03.15.07.01.43; Mon, 15 Mar 2021 07:02:06 -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="kvsmlU/G"; 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 S232483AbhCON66 (ORCPT + 99 others); Mon, 15 Mar 2021 09:58:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:58492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231343AbhCONyl (ORCPT ); Mon, 15 Mar 2021 09:54:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0247A64F15; Mon, 15 Mar 2021 13:54:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816481; bh=HOKIkv+gvghKcylRb81dDRRBZ2lhLoU1FFhNFxvpk6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kvsmlU/GLAHCMN22ksGb4efdPi4ViPd/+Z4A/xIGAeXz9hf5zCBK9G1mvh92oYuiT QyGjXkzjDyN/xBYCZABeL3EwUN/DWy+H5RJb1fGvj/ZImz4G4EhyH6sHPO6q+LWHP0 PkSuxNase4br1pHd9+pak3MDYv3xtqAo+dbXI9kU= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arvind Yadav , Andrey Konovalov , Hans Verkuil , Mauro Carvalho Chehab , Krzysztof Kozlowski Subject: [PATCH 4.4 69/75] media: hdpvr: Fix an error handling path in hdpvr_probe() Date: Mon, 15 Mar 2021 14:52:23 +0100 Message-Id: <20210315135210.517552146@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135208.252034256@linuxfoundation.org> References: <20210315135208.252034256@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: Greg Kroah-Hartman From: Arvind Yadav commit c0f71bbb810237a38734607ca4599632f7f5d47f upstream. Here, hdpvr_register_videodev() is responsible for setup and register a video device. Also defining and initializing a worker. hdpvr_register_videodev() is calling by hdpvr_probe at last. So no need to flush any work here. Unregister v4l2, free buffers and memory. If hdpvr_probe() will fail. Signed-off-by: Arvind Yadav Reported-by: Andrey Konovalov Tested-by: Andrey Konovalov Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab [krzk: backport to v4.4, still using single thread workqueue which is drained/destroyed now in proper step so it cannot be NULL] Signed-off-by: Krzysztof Kozlowski Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/hdpvr/hdpvr-core.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) --- a/drivers/media/usb/hdpvr/hdpvr-core.c +++ b/drivers/media/usb/hdpvr/hdpvr-core.c @@ -297,7 +297,7 @@ static int hdpvr_probe(struct usb_interf /* register v4l2_device early so it can be used for printks */ if (v4l2_device_register(&interface->dev, &dev->v4l2_dev)) { dev_err(&interface->dev, "v4l2_device_register failed\n"); - goto error; + goto error_free_dev; } mutex_init(&dev->io_mutex); @@ -306,7 +306,7 @@ static int hdpvr_probe(struct usb_interf dev->usbc_buf = kmalloc(64, GFP_KERNEL); if (!dev->usbc_buf) { v4l2_err(&dev->v4l2_dev, "Out of memory\n"); - goto error; + goto error_v4l2_unregister; } init_waitqueue_head(&dev->wait_buffer); @@ -314,7 +314,7 @@ static int hdpvr_probe(struct usb_interf dev->workqueue = create_singlethread_workqueue("hdpvr_buffer"); if (!dev->workqueue) - goto error; + goto err_free_usbc; dev->options = hdpvr_default_options; @@ -348,13 +348,13 @@ static int hdpvr_probe(struct usb_interf } if (!dev->bulk_in_endpointAddr) { v4l2_err(&dev->v4l2_dev, "Could not find bulk-in endpoint\n"); - goto error; + goto error_put_usb; } /* init the device */ if (hdpvr_device_init(dev)) { v4l2_err(&dev->v4l2_dev, "device init failed\n"); - goto error; + goto error_put_usb; } mutex_lock(&dev->io_mutex); @@ -362,7 +362,7 @@ static int hdpvr_probe(struct usb_interf mutex_unlock(&dev->io_mutex); v4l2_err(&dev->v4l2_dev, "allocating transfer buffers failed\n"); - goto error; + goto error_put_usb; } mutex_unlock(&dev->io_mutex); @@ -370,7 +370,7 @@ static int hdpvr_probe(struct usb_interf retval = hdpvr_register_i2c_adapter(dev); if (retval < 0) { v4l2_err(&dev->v4l2_dev, "i2c adapter register failed\n"); - goto error; + goto error_free_buffers; } client = hdpvr_register_ir_rx_i2c(dev); @@ -412,15 +412,20 @@ static int hdpvr_probe(struct usb_interf reg_fail: #if IS_ENABLED(CONFIG_I2C) i2c_del_adapter(&dev->i2c_adapter); +error_free_buffers: #endif + hdpvr_free_buffers(dev); +error_put_usb: + usb_put_dev(dev->udev); + /* Destroy single thread */ + destroy_workqueue(dev->workqueue); +err_free_usbc: + kfree(dev->usbc_buf); +error_v4l2_unregister: + v4l2_device_unregister(&dev->v4l2_dev); +error_free_dev: + kfree(dev); error: - if (dev) { - /* Destroy single thread */ - if (dev->workqueue) - destroy_workqueue(dev->workqueue); - /* this frees allocated memory */ - hdpvr_delete(dev); - } return retval; }