From patchwork Thu Jul 20 12:45:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 12340 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3117867vqt; Thu, 20 Jul 2023 06:27:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlFoDGYEwPmW15oTtoc9RqIXlre6AbzVuk152cW0ZkvdEozIj9h8FJ05r+A8Ned4gIKJFgcM X-Received: by 2002:a05:6a00:803:b0:666:e1f4:5153 with SMTP id m3-20020a056a00080300b00666e1f45153mr6757836pfk.0.1689859644715; Thu, 20 Jul 2023 06:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689859644; cv=none; d=google.com; s=arc-20160816; b=Gvs21/QcUs7xvnOLgXAJhC/v9PQHwoA9UH0nr0EyQ1ev7hnjbeWg0hFR7Vl2mgP1DH IcHYfF6POF2AtG7YhH6ALA2wk8LVKCS46xgsOxaPhIkBNBwVTMHluA5jF/Debi/FJmVd SV6XKUdiZPGmWGXFjTkwcDQYVsysHQLcsI1gmX/9Ka0fFJd3sGXCLtic3BVw4z1+TQB8 kLThpKjkqWL5iT8J5rwYiCrzGhaFgSGo9OFmH2ekXob9sHkescp/0GdfGEfwkOZo7ujI PukDf/tj9/ZLXm4l4irEwrcHUnWDYDq9KiB2fvNCReLlaiQt1RoQ4+U27WcfZbs7dHIR EZeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:content-transfer-encoding:mime-version :message-id:date:subject:from:dkim-signature; bh=m/3jjpqun6SNIW0SLQoZDJuBSaxqWwAgL5N29aSGtwU=; fh=tmUio+7MS/EkQoXm7KwEO9jjpqLQersHC1z4ZawnwsI=; b=BDmfVUCQlreOD1zVtuxGaAfg4Dd18u+U8cqOg3R20rTpmEzw53atv5Q5PwfPvk9q1d OuXLBKuuIKvyCQfvFgrn1+0cMWZXtiAewuO9QFnEqBnUyAOnnerqZjDulU8QTHjkkikd G5FIXO7Ht/lm2l+FVvwt1Sa6jZbHXVoRnN3Rv2mj/Ba1yK5+VFP1SFz3Wuo1O9nQqwRX U5EaoTNDOQ1DAd6Jc4h2Glkp6wRgnTKZGW8HfPbIwLccDlKbbJeKZaeWSZYBMi2pgEU6 gdYKimHRNEH3Xc4S1Js/kPSmwPb2RKIkNdADD2NoijCf1ZSAn9fjY8mb8HWoYsUzBLWC KjMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gMN3Nsmb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x10-20020a056a00188a00b0067dd7254cb0si1004379pfh.39.2023.07.20.06.27.11; Thu, 20 Jul 2023 06:27:24 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gMN3Nsmb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230479AbjGTMpX (ORCPT + 99 others); Thu, 20 Jul 2023 08:45:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbjGTMpV (ORCPT ); Thu, 20 Jul 2023 08:45:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30AFD268E; Thu, 20 Jul 2023 05:45:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BDD0A61A77; Thu, 20 Jul 2023 12:45:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7347DC433C8; Thu, 20 Jul 2023 12:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689857116; bh=5d6Vcd3i0QdevHm+PGdaD3ugaO4LY83MGq1tZNki+JU=; h=From:Subject:Date:To:Cc:From; b=gMN3NsmbToZ5uGhZvME1SxRJMORTFK3LQXLvryIx2Dsznsk4S1qt+y5boSN71/Wy3 bUejr9nX9rJGlDdmRvigTsckCyxY2xWPJ61qaSDKYDrAugC3h1/ipCDWiA+asPyHHZ dLU5HY+ea2Rz8wIXh3YTotGmarkHWG5yBnlx00gVqJoPGrPrQz+Y5OuQzggyYOyYz2 MHZvLHok1afyi8rwAqGeurCWYgr3m6wi4KFh7Xa5qvfrXoXMbiPWjY/EuXxTd8+jDU cd6wL2VUK3u+TKZhgt8ElKm+6wfg7STBK+4IwvT6TGUlH/ymEJBirib8SXhAe4VSD1 AhHmCFAexrhCA== From: Maxime Ripard Subject: [PATCH v3 0/3] drivers: base: Add tests showing devm handling inconsistencies Date: Thu, 20 Jul 2023 14:45:06 +0200 Message-Id: <20230720-kunit-devm-inconsistencies-test-v3-0-6aa7e074f373@kernel.org> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAFIsuWQC/5XOOw7CMBAE0Ksg12zkTz5AlXsgisRZiEVYI9tYo Ch3Z5MTQDlTvJlZRAwOozjtZhEwu+g8cTD7nbBjRzcEN3AWWmojjT7C/UUuwYD5AY6sp+hiQrJ sQMKYoMKqawapsJaDYKXvIkIfOrIjO/SaJi6fAa/uvc2eL5xHRnz4bC+yWtvfB7MCCdYYpRtZH kxTtRYD+SIhL6541n+CmkF1vGLfKDzUZd/eGcSp8OEmLsuyfAH7RFTkNQEAAA== To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Brendan Higgins , David Gow , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Maxime Ripard X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2230; i=mripard@kernel.org; h=from:subject:message-id; bh=5d6Vcd3i0QdevHm+PGdaD3ugaO4LY83MGq1tZNki+JU=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDCk7dSL0RH6yrsxh/bi75VOwPLdjovf6G2UTI9eeq/i/X Sj98vQbHaUsDGJcDLJiiiwxwuZL4k7Net3JxjcPZg4rE8gQBi5OAZiItgPDP7P7LopxU297bSm+ K3v3leW6xaVrrQrMU/lz/fg5aoQviDP8sz/0dsnFeUwJUt+UKss4y+YIcrk7rnb1spXTajRKvSv PCQA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: 1771946266587881509 X-GMAIL-MSGID: 1771946266587881509 Hi, This follows the discussion here: https://lore.kernel.org/linux-kselftest/20230324123157.bbwvfq4gsxnlnfwb@houat/ This shows a couple of inconsistencies with regard to how device-managed resources are cleaned up. Basically, devm resources will only be cleaned up if the device is attached to a bus and bound to a driver. Failing any of these cases, a call to device_unregister will not end up in the devm resources being released. We had to work around it in DRM to provide helpers to create a device for kunit tests, but the current discussion around creating similar, generic, helpers for kunit resumed interest in fixing this. This can be tested using the command: ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/base/test/ I added the fix David suggested back in that discussion which does fix the tests. The SoB is missing, since David didn't provide it back then. Let me know what you think, Maxime Signed-off-by: Maxime Ripard --- Changes in v3: - Reworded the commit logs according to David's feedback - Rebased on current next - Link to v2: https://lore.kernel.org/r/20230329-kunit-devm-inconsistencies-test-v2-0-19feb71e864b@kernel.org Changes in v2: - Use an init function - Document the tests - Add a fix for the bugs - Link to v1: https://lore.kernel.org/r/20230329-kunit-devm-inconsistencies-test-v1-0-c33127048375@cerno.tech --- David Gow (1): drivers: base: Free devm resources when unregistering a device Maxime Ripard (2): drivers: base: Add basic devm tests for root devices drivers: base: Add basic devm tests for platform devices drivers/base/core.c | 11 ++ drivers/base/test/.kunitconfig | 2 + drivers/base/test/Kconfig | 4 + drivers/base/test/Makefile | 3 + drivers/base/test/platform-device-test.c | 220 +++++++++++++++++++++++++++++++ drivers/base/test/root-device-test.c | 108 +++++++++++++++ 6 files changed, 348 insertions(+) --- base-commit: c58c49dd89324b18a812762a2bfa5a0458e4f252 change-id: 20230329-kunit-devm-inconsistencies-test-5e5a7d01e60d Best regards,