From patchwork Fri Aug 4 09:09:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 131076 Return-Path: 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 + 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 ); 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 To: Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko Cc: Andy Shevchenko , Dhruva Gole , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , John Ogness , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Tomi Valkeinen 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 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773292664130753243 X-GMAIL-MSGID: 1773293812658044960 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 Signed-off-by: Tony Lindgren Tested-by: Tomi Valkeinen --- 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)