Message ID | 20230804090909.51529-1-tony@atomide.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp162567vqb; Fri, 4 Aug 2023 03:26:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENf1Rnhfp5jo2Z/f0wHmJykfiAVXXK9hmaPqaRwGNS7xt8tkN6ABmRRBMwgfWQFym3nWVz X-Received: by 2002:a05:6a20:5494:b0:12d:ba1e:d763 with SMTP id i20-20020a056a20549400b0012dba1ed763mr1369569pzk.7.1691144764590; Fri, 04 Aug 2023 03:26:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691144764; cv=none; d=google.com; s=arc-20160816; b=fLtwSeHP+/buqiq+tYkfubNxdeBlm2MB9V1l6BumNV2AjheIng/c1oczONFrxz2VDh /kBcuKrDdcMCzdy4zxEpNpr6ZCUTEsSrLIjonYMsdCpdOuVm2kvhLzkp1t2AopbyKwEc +1S/DwrOoWlALvceoDZzJ0OZbotdbQphF7It0IA8xbz5BXUsbqKhxxaK7XuhYs891V/H z4WkoW+XY7qaWmgb446g8Mmo5Wz0k2hbZ2AggIoX9E0nHtff6kXUcVbZLnY98d3G4dqt 0jvSFHySJmaBLrQi9KvORId0EBJ3xpci5lOgnJqFWDaQCnYKi8L9t2Z6wHZ/wcJzk4nk OJPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=P2cwHs796UKFceR9H1/a7clSeQyBqb96wm4wFxMxKi4=; fh=1yNFhKtNCYscn3dxf02lXpBSKv5jgHib/3xmD7ggU5A=; b=zL+Yr3aBlsJkpWzEswgS6V92+4vWZOes47qiB31dk9PyOJUQoOiCgClfUyXHQ9I+z5 M1ynyo/pr40YciNMd7ixP7sCnXYZdbQ6GsyyNCpELSDj7W6WS5A3RR9KazcTvN9FDZzL xdMvGmsHzBzQiKkn0Cn2bqZ5ZInwqdOx0utyflvwqkyO5Et4rPWduwLhECoPU/qrTQhm srGdJ5SOwYoiWC7oPZ8TDDmoeS9p2F3mK9KItqZ/4G48LBdv1Vld7k6GVY944WQyk0F3 6H7WP22/1aMKLqWBBC0YLAN3xTQIA+IaXpDVRV/osJITFW6smtN9GJXdxHW1qXJ8oMjY zvyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j10-20020a170902da8a00b001b8944aa943si1585139plx.315.2023.08.04.03.25.51; Fri, 04 Aug 2023 03:26:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230090AbjHDJMj (ORCPT <rfc822;sukrut.bellary@gmail.com> + 99 others); Fri, 4 Aug 2023 05:12:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230086AbjHDJMG (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 4 Aug 2023 05:12:06 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4A74649DA; Fri, 4 Aug 2023 02:09:14 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 87CC580F7; Fri, 4 Aug 2023 09:09:11 +0000 (UTC) From: Tony Lindgren <tony@atomide.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jiri Slaby <jirislaby@kernel.org>, Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Andy Shevchenko <andriy.shevchenko@intel.com>, Dhruva Gole <d-gole@ti.com>, =?utf-8?q?Ilpo_J=C3=A4rvinen?= <ilpo.jarvinen@linux.intel.com>, John Ogness <john.ogness@linutronix.de>, Johan Hovold <johan@kernel.org>, Sebastian Andrzej Siewior <bigeasy@linutronix.de>, Vignesh Raghavendra <vigneshr@ti.com>, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Subject: [PATCH] serial: core: Fix kmemleak issue for serial core device remove Date: Fri, 4 Aug 2023 12:09:07 +0300 Message-ID: <20230804090909.51529-1-tony@atomide.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773292664130753243 X-GMAIL-MSGID: 1773293812658044960 |
Series |
serial: core: Fix kmemleak issue for serial core device remove
|
|
Commit Message
Tony Lindgren
Aug. 4, 2023, 9:09 a.m. UTC
Kmemleak reports issues for serial8250 ports after the hardware specific
driver takes over on boot as noted by Tomi.
The kerneldoc for device_initialize() says we must call device_put()
after calling device_initialize(). We are calling device_put() on the
error path, but are missing it from the device remove path. This causes
release() to never get called for the devices on remove.
Let's add the missing put_device() calls for both serial ctrl and
port devices.
Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
Reported-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
drivers/tty/serial/serial_base_bus.c | 2 ++
1 file changed, 2 insertions(+)
Comments
On 04/08/2023 12:09, Tony Lindgren wrote: > Kmemleak reports issues for serial8250 ports after the hardware specific > driver takes over on boot as noted by Tomi. > > The kerneldoc for device_initialize() says we must call device_put() > after calling device_initialize(). We are calling device_put() on the > error path, but are missing it from the device remove path. This causes > release() to never get called for the devices on remove. > > Let's add the missing put_device() calls for both serial ctrl and > port devices. > > Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM") > Reported-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > Signed-off-by: Tony Lindgren <tony@atomide.com> > --- > drivers/tty/serial/serial_base_bus.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/serial_base_bus.c > --- a/drivers/tty/serial/serial_base_bus.c > +++ b/drivers/tty/serial/serial_base_bus.c > @@ -99,6 +99,7 @@ void serial_base_ctrl_device_remove(struct serial_ctrl_device *ctrl_dev) > return; > > device_del(&ctrl_dev->dev); > + put_device(&ctrl_dev->dev); > } > > struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port, > @@ -174,6 +175,7 @@ void serial_base_port_device_remove(struct serial_port_device *port_dev) > return; > > device_del(&port_dev->dev); > + put_device(&port_dev->dev); > } > > static int serial_base_init(void) Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Tomi
On Fri, Aug 04, 2023 at 12:21:05PM +0300, Tony Lindgren wrote: > * Jiri Slaby <jirislaby@kernel.org> [230804 09:16]: > > On 04. 08. 23, 11:09, Tony Lindgren wrote: > > > Kmemleak reports issues for serial8250 ports after the hardware specific > > > driver takes over on boot as noted by Tomi. > > > > > > The kerneldoc for device_initialize() says we must call device_put() > > > after calling device_initialize(). We are calling device_put() on the > > > error path, but are missing it from the device remove path. This causes > > > release() to never get called for the devices on remove. > > > > > > Let's add the missing put_device() calls for both serial ctrl and > > > port devices. > > > > > > Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM") > > > Reported-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > > > Signed-off-by: Tony Lindgren <tony@atomide.com> > > > --- > > > drivers/tty/serial/serial_base_bus.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/serial_base_bus.c > > > --- a/drivers/tty/serial/serial_base_bus.c > > > +++ b/drivers/tty/serial/serial_base_bus.c > > > @@ -99,6 +99,7 @@ void serial_base_ctrl_device_remove(struct serial_ctrl_device *ctrl_dev) > > > return; > > > device_del(&ctrl_dev->dev); > > > + put_device(&ctrl_dev->dev); > > > } > > > struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port, > > > @@ -174,6 +175,7 @@ void serial_base_port_device_remove(struct serial_port_device *port_dev) > > > return; > > > device_del(&port_dev->dev); > > > + put_device(&port_dev->dev); > > > > I didn't check the code, but device_unregister()? > > I thought about that as it does the same, but since we're not calling > device_register() I felt it would be and unpaired call. No objections to > changing to use device_unregister() naturally if folks prefer that. This is fine as device_register() isn't happening, thanks. greg k-h
diff --git a/drivers/tty/serial/serial_base_bus.c b/drivers/tty/serial/serial_base_bus.c --- a/drivers/tty/serial/serial_base_bus.c +++ b/drivers/tty/serial/serial_base_bus.c @@ -99,6 +99,7 @@ void serial_base_ctrl_device_remove(struct serial_ctrl_device *ctrl_dev) return; device_del(&ctrl_dev->dev); + put_device(&ctrl_dev->dev); } struct serial_ctrl_device *serial_base_ctrl_add(struct uart_port *port, @@ -174,6 +175,7 @@ void serial_base_port_device_remove(struct serial_port_device *port_dev) return; device_del(&port_dev->dev); + put_device(&port_dev->dev); } static int serial_base_init(void)