From patchwork Wed Mar 7 11:37:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arvind Yadav X-Patchwork-Id: 10263861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 729D36016D for ; Wed, 7 Mar 2018 11:38:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62069294A5 for ; Wed, 7 Mar 2018 11:38:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 530EC294AD; Wed, 7 Mar 2018 11:38:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E321D294A5 for ; Wed, 7 Mar 2018 11:38:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751257AbeCGLiZ (ORCPT ); Wed, 7 Mar 2018 06:38:25 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:43980 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751171AbeCGLiY (ORCPT ); Wed, 7 Mar 2018 06:38:24 -0500 Received: by mail-io0-f194.google.com with SMTP id l12so2671592ioc.10; Wed, 07 Mar 2018 03:38:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=oQyUwjnLROGFAsLhGL1n4e7JmsHtAkLrXYOOEuSh5ts=; b=nR3An5+XVfZIMrLkzXdJ53N4tvkgwSPmDPWloPYtKDc/l5wuWzFnta5tKAHBKhc5lJ ap5y+83C3q6Z7ayHxOCR6Ag4qry8T674ylZW/BlBmuVJst3dtyqIx/eGpSsTloOrFz/o XqAT3cFLqgWkambT8b8uBP0L5KQGxSSO53bgHUsFLsbhBJDiGSaAaK+A8ajQlsobcs5m UglVMtd6g6t3IJhfmuU+KpmsACmVc/NI0z84XQ2pXMi6mD7VJw2nGf1T4QP49l6v8iE9 I7FFrhKw+4VjEnHdBreiQLJsoL5S5M3/sZGwDBBZKxxhD5BM+XqBoHUZcgAIU17pnxdy H1PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oQyUwjnLROGFAsLhGL1n4e7JmsHtAkLrXYOOEuSh5ts=; b=IY7JbbBt6xt6Ivq9i6JsBtNdO9heVitI23KZ0wbJaNMRXJBIjnB6ls85qWs0zQ3R2V TUsnBXujr+2AbdgMtkhrCRi1YnPlJJG2fVYyGmX0/9aDOw/2mV5QAwS2dyC0nVBH5XUv zgO5nBQK/d0SQZTZWe4t2VtHsrNyVWZjOQTcNNTEtJUgFLNK7vDGEnuPcHFbK1jaXAcx Ki5xLI8N1/RgwjpTEQ9bBaIg8eDfGQcZMUV2X2EwiN8bFVX8KkxfYnhfhiGEvmicsJix SrSzIn/o+s0/wrNg073PRvD8GensCXh6skghxY6q0W6If396OWPaJF0C4QHNlF260yDO jlog== X-Gm-Message-State: APf1xPCuYl2oOLdxesB49MpYahSK7Xd93GJ/P0P7kR51aphVyK8vM0OD df1KpoFerApRRpWIi3SfE0Q= X-Google-Smtp-Source: AG47ELsj6+r793NCOl9G6Crk1dOUYXAxpB6J32y5fUoRqjrR2yh91WWVVIl3A7X5QDAWhOqnBj7rnA== X-Received: by 10.107.14.73 with SMTP id 70mr25149811ioo.258.1520422703536; Wed, 07 Mar 2018 03:38:23 -0800 (PST) Received: from symbol-HP-Z420-Workstation.zebra.lan ([149.23.17.254]) by smtp.googlemail.com with ESMTPSA id j125sm8920696ite.40.2018.03.07.03.38.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Mar 2018 03:38:22 -0800 (PST) From: Arvind Yadav To: lduncan@suse.com, cleech@redhat.com, jejb@linux.vnet.ibm.com, martin.petersen@oracle.com Cc: linux-kernel@vger.kernel.org, open-iscsi@googlegroups.com, linux-scsi@vger.kernel.org Subject: [PATCH] scsi: scsi_transport_iscsi: use put_device() instead of kfree() Date: Wed, 7 Mar 2018 17:07:33 +0530 Message-Id: X-Mailer: git-send-email 1.9.1 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Never directly free @dev after calling device_register(), even if it returned an error! Always use put_device() to give up the reference initialized. Signed-off-by: Arvind Yadav Signed-off-by: Chris Leech --- drivers/scsi/scsi_transport_iscsi.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index f4b52b4..aacb7ab 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -221,8 +221,10 @@ struct iscsi_endpoint * ep->dev.class = &iscsi_endpoint_class; dev_set_name(&ep->dev, "ep-%llu", (unsigned long long) id); err = device_register(&ep->dev); - if (err) - goto free_ep; + if (err) { + put_device(&ep->dev); + return NULL; + } err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group); if (err) @@ -235,10 +237,6 @@ struct iscsi_endpoint * unregister_dev: device_unregister(&ep->dev); return NULL; - -free_ep: - kfree(ep); - return NULL; } EXPORT_SYMBOL_GPL(iscsi_create_endpoint); @@ -783,7 +781,7 @@ struct iscsi_iface * free_iface: put_device(iface->dev.parent); - kfree(iface); + put_device(&iface->dev); return NULL; } EXPORT_SYMBOL_GPL(iscsi_create_iface); @@ -1260,7 +1258,7 @@ struct iscsi_bus_flash_session * return fnode_sess; free_fnode_sess: - kfree(fnode_sess); + put_device(&fnode_sess->dev); return NULL; } EXPORT_SYMBOL_GPL(iscsi_create_flashnode_sess); @@ -1308,7 +1306,7 @@ struct iscsi_bus_flash_conn * return fnode_conn; free_fnode_conn: - kfree(fnode_conn); + put_device(&fnode_conn->dev); return NULL; } EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn); @@ -2268,6 +2266,8 @@ struct iscsi_cls_conn * release_parent_ref: put_device(&session->dev); + put_device(&conn->dev); + conn = NULL; free_conn: kfree(conn); return NULL; @@ -4420,8 +4420,10 @@ struct scsi_transport_template * priv->dev.class = &iscsi_transport_class; dev_set_name(&priv->dev, "%s", tt->name); err = device_register(&priv->dev); - if (err) - goto free_priv; + if (err) { + put_device(&priv->dev); + return NULL; + } err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group); if (err) @@ -4456,9 +4458,6 @@ struct scsi_transport_template * unregister_dev: device_unregister(&priv->dev); return NULL; -free_priv: - kfree(priv); - return NULL; } EXPORT_SYMBOL_GPL(iscsi_register_transport);