From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752976AbcKRLZY (ORCPT ); Fri, 18 Nov 2016 06:25:24 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:60168 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752320AbcKRLZW (ORCPT ); Fri, 18 Nov 2016 06:25:22 -0500 DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org 600446265F Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=kvalo@codeaurora.org Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: mwifiex: don't do unbalanced free()'ing in cleanup_if() From: Kalle Valo In-Reply-To: <1477524560-49226-1-git-send-email-briannorris@chromium.org> References: <1477524560-49226-1-git-send-email-briannorris@chromium.org> To: Brian Norris Cc: Amitkumar Karwar , Nishant Sarmukadam , , linux-wireless@vger.kernel.org, Cathy Luo , Rajat Jain , Dmitry Torokhov , Brian Norris User-Agent: pwcli/0.0.0-git (https://github.com/kvalo/pwcli/) Python/2.7.3 Message-Id: <20161118112521.4F5316265F@smtp.codeaurora.org> Date: Fri, 18 Nov 2016 11:25:21 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Brian Norris wrote: > The cleanup_if() callback is the inverse of init_if(). We allocate our > 'card' interface structure in the probe() function, but we free it in > cleanup_if(). That gives a few problems: > (a) we leak this memory if probe() fails before we reach init_if() > (b) we can't safely utilize 'card' after cleanup_if() -- namely, in > remove() or suspend(), both of which might race with the cleanup > paths in our asynchronous FW initialization path > > Solution: just use devm_kzalloc(), which will free this structure > properly when the device is removed -- and drop the set_drvdata(..., > NULL), since the driver core does this for us. This also removes the > temptation to use drvdata == NULL as a hack for checking if the device > has been "cleaned up." > > I *do* leave the set_drvdata(..., NULL) for the hacky SDIO > mwifiex_recreate_adapter(), since the device core won't be able to clear > that one for us. > > Signed-off-by: Brian Norris Patch applied to wireless-drivers-next.git, thanks. 66b9c182538e mwifiex: don't do unbalanced free()'ing in cleanup_if() -- https://patchwork.kernel.org/patch/9398689/ Documentation about submitting wireless patches and checking status from patchwork: https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches