Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp52775imu; Thu, 8 Nov 2018 14:38:27 -0800 (PST) X-Google-Smtp-Source: AJdET5ceGzgWL+f7ScrBtTyosAz5hKFYCNNC5YTpnmgoF1482HxI/fIKErd5JkoQHlMMaV9i8LoP X-Received: by 2002:a17:902:700b:: with SMTP id y11-v6mr6275519plk.323.1541716707405; Thu, 08 Nov 2018 14:38:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541716707; cv=none; d=google.com; s=arc-20160816; b=IKu4oCmZcjA6L/dZ9VUPiA+gXFvrnkYDWLeayrQamNXNA8DyQn3VpE7THa5D7+SXwq qvwHXx4IXQRBcuIgdxkzCLrKh7JejozcpvQDC1iG1VAbbw6Ljgm97w3bEkjgo58f17dt SHZvHV82gR2QDU42IL9WMYm/9oB0XnHN6ck4M2Bt0ipoyQg09V1jNDUaoRs4pFDvceMZ vbDYO8ABehsOFJeztSi5WTYwCTWQCTE6h6+fHzTHQzeiW//NR1ELvx6ODy43yf7cP+DG +b+5Y4PKHYlglW1AmXca/Z/4EJjJfj4/Hn5UImODKL3UGgv/hsF9VEtXEtElGh2S+f1w Wkcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JDfqp5d70Oi5BxeSgkNyIFk3k1An7aoL4B+k92b+x7I=; b=k7TI8H4TV3xCPmR1Ld6SNKz/ezEkk1doQ38bgJxXPIkEAm5IpbPzYjvwfrj9CQTtgM sEWnq8nES4MURjAVol6Pbt5+qVLnEmOztw5kkHOzZyAs2foUC+hR149cXztkwcIkwNxR nIewoZ4qAXbhrBPY88GZLMt1rn5el1KHix4sMFjHleyVRXa55LCsyd9iMgeG6Z+nKbGs 2jnGns1SwbL04AXLVa+rDDfQqchwyY3u7qNQm1fKQTfJj1q26jHYgOF2IFvZScqbTXMa Ky5hPUzcIkoQ6o9pKZw5eKN4A8kiepFQETkCJrC/+sDgoDvA0pkO8riih629aOR+KqdE 459g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NOiYVuSR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m20si4758650pgk.323.2018.11.08.14.38.11; Thu, 08 Nov 2018 14:38:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NOiYVuSR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729100AbeKIIOJ (ORCPT + 99 others); Fri, 9 Nov 2018 03:14:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:53764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729243AbeKIHgX (ORCPT ); Fri, 9 Nov 2018 02:36:23 -0500 Received: from localhost (unknown [208.72.13.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9807C21019; Thu, 8 Nov 2018 21:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714335; bh=1wRNKoTmLwbpXecmCjnfxJuvRxzWvFbGa3IUOorHxb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NOiYVuSRHOH7YsxKQEyebncwS48Xo2ASLtUczP+mIkWrd0NUqkXawDlPsR/bFo42f ljhp3FTPy4Z+S+tWSvbtlpqq954jwiM+LfK1S7S72OdQBg/nYnW1RGv4AONbmk0iXg tFGOsw5FUxR5IjxYy93XAM7Kj0aISisI2TaNAMpE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Vyukov , Paul Bolle , Tilman Schmidt , "David S. Miller" , Sasha Levin Subject: [PATCH 4.4 022/114] ser_gigaset: use container_of() instead of detour Date: Thu, 8 Nov 2018 13:50:37 -0800 Message-Id: <20181108215101.164658460@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 8d2c3ab4445640957d136caa3629857d63544a2a ] The purpose of gigaset_device_release() is to kfree() the struct ser_cardstate that contains our struct device. This is done via a bit of a detour. First we make our struct device's driver_data point to the container of our struct ser_cardstate (which is a struct cardstate). In gigaset_device_release() we then retrieve that driver_data again. And after that we finally kfree() the struct ser_cardstate that was saved in the struct cardstate. All of this can be achieved much easier by using container_of() to get from our struct device to its container, struct ser_cardstate. Do so. Note that at the time the detour was implemented commit b8b2c7d845d5 ("base/platform: assert that dev_pm_domain callbacks are called unconditionally") had just entered the tree. That commit disconnected our platform_device and our platform_driver. These were reconnected again in v4.5-rc2 through commit 25cad69f21f5 ("base/platform: Fix platform drivers with no probe callback"). And one of the consequences of that fix was that it broke the detour via driver_data. That's because it made __device_release_driver() stop being a NOP for our struct device and actually do stuff again. One of the things it now does, is setting our driver_data to NULL. That, in turn, makes it impossible for gigaset_device_release() to get to our struct cardstate. Which has the net effect of leaking a struct ser_cardstate at every call of this driver's tty close() operation. So using container_of() has the additional benefit of actually working. Reported-by: Dmitry Vyukov Tested-by: Dmitry Vyukov Signed-off-by: Paul Bolle Acked-by: Tilman Schmidt Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/isdn/gigaset/ser-gigaset.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c index 74bf1a17ae7c..b90776ef56ec 100644 --- a/drivers/isdn/gigaset/ser-gigaset.c +++ b/drivers/isdn/gigaset/ser-gigaset.c @@ -373,13 +373,7 @@ static void gigaset_freecshw(struct cardstate *cs) static void gigaset_device_release(struct device *dev) { - struct cardstate *cs = dev_get_drvdata(dev); - - if (!cs) - return; - dev_set_drvdata(dev, NULL); - kfree(cs->hw.ser); - cs->hw.ser = NULL; + kfree(container_of(dev, struct ser_cardstate, dev.dev)); } /* @@ -408,7 +402,6 @@ static int gigaset_initcshw(struct cardstate *cs) cs->hw.ser = NULL; return rc; } - dev_set_drvdata(&cs->hw.ser->dev.dev, cs); tasklet_init(&cs->write_tasklet, gigaset_modem_fill, (unsigned long) cs); -- 2.17.1