From patchwork Thu Jul 12 20:30:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Battersby X-Patchwork-Id: 10522263 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 239796032C for ; Thu, 12 Jul 2018 20:30:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12FC82982F for ; Thu, 12 Jul 2018 20:30:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10B8729BA7; Thu, 12 Jul 2018 20:30:49 +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 6D3D029CB7 for ; Thu, 12 Jul 2018 20:30:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732520AbeGLUl6 (ORCPT ); Thu, 12 Jul 2018 16:41:58 -0400 Received: from mail.cybernetics.com ([173.71.130.66]:47336 "EHLO mail.cybernetics.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732512AbeGLUl6 (ORCPT ); Thu, 12 Jul 2018 16:41:58 -0400 X-ASG-Debug-ID: 1531427445-0fb3b01fb32bcd60001-ziuLRu Received: from cybernetics.com ([10.157.1.126]) by mail.cybernetics.com with ESMTP id aHIBdzNzgtQIYVCY (version=SSLv3 cipher=DES-CBC3-SHA bits=112 verify=NO); Thu, 12 Jul 2018 16:30:45 -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 8279048; Thu, 12 Jul 2018 16:30:45 -0400 Subject: Re: [PATCH] sg: fix minor memory leak in error path To: Bart Van Assche , "linux-scsi@vger.kernel.org" , "dgilbert@interlog.com" , "jejb@linux.vnet.ibm.com" X-ASG-Orig-Subj: Re: [PATCH] sg: fix minor memory leak in error path References: <3c90c434-0ce4-c8df-1359-1453be766043@cybernetics.com> From: Tony Battersby Message-ID: <4a89b424-b88e-98b6-5261-df23dff342f0@cybernetics.com> Date: Thu, 12 Jul 2018 16:30:45 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Barracuda-Connect: UNKNOWN[10.157.1.126] X-Barracuda-Start-Time: 1531427445 X-Barracuda-Encrypted: DES-CBC3-SHA X-Barracuda-URL: https://10.157.1.122:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 767 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. Fixes: cc833acbee9d ("sg: O_EXCL and other lock handling") Cc: Reviewed-by: Ewan D. Milne Signed-off-by: Tony Battersby Reviewed-by: Bart Van Assche --- Resending to include the requested fixes: / cc: stable tags. 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);