From mboxrd@z Thu Jan 1 00:00:00 1970 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=-2.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 DBED8C432C0 for ; Mon, 25 Nov 2019 16:13:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6FE9A20409 for ; Mon, 25 Nov 2019 16:13:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="d8p9vafO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FE9A20409 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VNceExqydpf5g2Wnd+7Ht2FtFt/l/01B1iEFy8XqKsY=; b=d8p9vafOyyB9I1 L05Oc040zPxp7+I8LNHip5k0YVoiI/zAAOrr+GuPDwy/kHp50JfMm5hsQdp4YIXZSQeGvIHJ2ZVRV 9esrtiPC/2oZ3cMYusPqS4dvwHMxB0g8I9cSgw3zc3kLBEsbajtrQutDxR//5827BZPshmoYElMmS i5isUyo1joyIEuxOlrNZcadPGtUOH6+KJdrZ+0/SMpHzLeX9NJ0lKWaZZm9fTAhpYnTzYnx96oXCK Ywi4TuOMlYVTSOqTqOPnzNxZm/CRdVUSGO6K/GplAjpDkvxMTHojOvhAKpJYR4npMciz8NFsxqCCa 5I3bXn5E5mR/XySV00Iw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iZGzf-0006Zr-Up; Mon, 25 Nov 2019 16:13:43 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iZGzd-0006Z1-6s for linux-arm-kernel@lists.infradead.org; Mon, 25 Nov 2019 16:13:42 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B8F5A31B; Mon, 25 Nov 2019 08:13:38 -0800 (PST) Received: from bogus (e107155-lin.cambridge.arm.com [10.1.196.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DD1BD3F6C4; Mon, 25 Nov 2019 08:13:37 -0800 (PST) Date: Mon, 25 Nov 2019 16:13:31 +0000 From: Sudeep Holla To: Wen Yang Subject: Re: [PATCH] firmware: arm_scmi: avoid double free in error flow Message-ID: <20191125161313.GA1157@bogus> References: <20191125155409.9948-1-wenyang@linux.alibaba.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20191125155409.9948-1-wenyang@linux.alibaba.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191125_081341_293773_2633F4E8 X-CRM114-Status: GOOD ( 12.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sudeep Holla , linux-arm-kernel@lists.infradead.org, Arnd Bergmann , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Nov 25, 2019 at 11:54:09PM +0800, Wen Yang wrote: > If device_register() fails, both put_device() and kfree() > are called, ending with a double free of the scmi_dev. > Correct. > Calling kfree() is needed only when a failure happens between the > allocation of the scmi_dev and its registration, so move it to > there and remove it from the error flow. > kstrdup_const can fail and in that case device is not yet registered, so we need to free. Since device_register() calls put_device() on failure too, I would just drop it as it's unnecessary, not sure why I have added it in the first place. Can you re-spin the patch dropping put_device and renaming put_dev label to something like free_const. -- Regards, Sudeep _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel