From patchwork Thu Jul 12 18:46:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Battersby X-Patchwork-Id: 10522203 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 DAF18602B3 for ; Thu, 12 Jul 2018 19:01:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3F202927C for ; Thu, 12 Jul 2018 19:01:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C225F28FCC; Thu, 12 Jul 2018 19:01:52 +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.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 2FBA4292E3 for ; Thu, 12 Jul 2018 19:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726820AbeGLTMl (ORCPT ); Thu, 12 Jul 2018 15:12:41 -0400 Received: from mail.cybernetics.com ([173.71.130.66]:44792 "EHLO mail.cybernetics.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726561AbeGLTMl (ORCPT ); Thu, 12 Jul 2018 15:12:41 -0400 X-Greylist: delayed 912 seconds by postgrey-1.27 at vger.kernel.org; Thu, 12 Jul 2018 15:12:41 EDT X-ASG-Debug-ID: 1531421195-0fb3b01fb32bbeb0001-ziuLRu Received: from cybernetics.com ([10.157.1.126]) by mail.cybernetics.com with ESMTP id cgYvsoPZ9BHtSOGs (version=SSLv3 cipher=DES-CBC3-SHA bits=112 verify=NO); Thu, 12 Jul 2018 14:46:36 -0400 (EDT) X-Barracuda-Envelope-From: tonyb@cybernetics.com X-ASG-Whitelist: Client Received: from [10.157.2.224] (account tonyb HELO [192.168.200.1]) by cybernetics.com (CommuniGate Pro SMTP 5.1.14) with ESMTPSA id 8278609; Thu, 12 Jul 2018 14:46:35 -0400 To: linux-scsi , Doug Gilbert , "James E.J. Bottomley" From: Tony Battersby Subject: [PATCH] sg: fix minor memory leak in error path Message-ID: <3c90c434-0ce4-c8df-1359-1453be766043@cybernetics.com> X-ASG-Orig-Subj: [PATCH] sg: fix minor memory leak in error path Date: Thu, 12 Jul 2018 14:46:35 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 Content-Language: en-US X-Barracuda-Connect: UNKNOWN[10.157.1.126] X-Barracuda-Start-Time: 1531421196 X-Barracuda-Encrypted: DES-CBC3-SHA X-Barracuda-URL: https://10.157.1.122:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 561 X-Virus-Scanned: by bsmtpd at cybernetics.com X-Barracuda-BRTS-Status: 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 Fix a minor memory leak when there is an error opening a /dev/sg device. Signed-off-by: Tony Battersby Reviewed-by: Ewan D. Milne Acked-by: Douglas Gilbert diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index cd2fdac..2962a38 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -2185,6 +2185,7 @@ sg_add_sfp(Sg_device * sdp) write_lock_irqsave(&sdp->sfd_lock, iflags); if (atomic_read(&sdp->detaching)) { write_unlock_irqrestore(&sdp->sfd_lock, iflags); + kfree(sfp); return ERR_PTR(-ENODEV); } list_add_tail(&sfp->sfd_siblings, &sdp->sfds);