Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2759741rwl; Mon, 27 Mar 2023 05:04:48 -0700 (PDT) X-Google-Smtp-Source: AKy350Yjo5T3EeKD+Uo8tRYD1YF9vRgunWWYsJ/WtxY/NBmLvMNQaH0JD6J0sLFEmnT9t6cRHiCe X-Received: by 2002:a17:906:ee8b:b0:93e:8791:7d8e with SMTP id wt11-20020a170906ee8b00b0093e87917d8emr12252387ejb.2.1679918688453; Mon, 27 Mar 2023 05:04:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679918688; cv=none; d=google.com; s=arc-20160816; b=A+ET1nt1ff/A0nnDjbk4pA+jB6DEKw8uZw5nJWZsKxj0KGgSB38VHNKA/St950ovTX MRnGe0XXzFjSO9yvo/vVzRXlG0F48HX+t82EKlXcPOnRbgKiysATODFG967qluLznA0h 5xk0qAxg/aPVp5gklQfdGK3Tv3O1gm6jKYOr1FKuJqLkM3fbEEJpKdjMjPlxaSEW2FjC qLnJX6slivKSnIJF2RzO6T/avYfKV3DMj6jLoEdtYdY7+lvWgWWC9me0Onesi4xq2hNU SiqXUXTnZhZsF76BjWcOmU1s4AlMXJTkr9A8qpcwXpQ6SHM0Tn1fbCq5rA+zEU8QmBw4 FZYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DnVE2QyklB6KPlxLYqugnfQtyAJMTIFxzleVNAIorcY=; b=T7j96VJrwAwp2NgBpVNKac0OlYjv9wEm8C2m0eTIg08nzD+oCcpw6Cdb4yLnCSYwmz ZVwwh0zaPtBLFe2Y28Q3e2usiQPuCLaHUyH4RymNfSAz2l5vm2ZPe02jqblihnuMHcaS Ze9ySHk+OQRugSg9u4RURAEIuRcNnoIC+wtY7IDY50BMmFM3ankPmXpYw/hwx0i3ngZt 33Iu1ReMSmfwFl6VtDzDtrTa4zX1Gla3lRx3A/BQLMMQIUpLCPpVmwzr65VFjvpFKX7x dpLmXF3RSjdCMY3JnhfLH5VEY55cZsJbogGiLZKWngweJvYJJt5PvpUHcbjWgk7ktZjP dosw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qqjwaYgy; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ss24-20020a170907c01800b009334a8e8c07si22600551ejc.103.2023.03.27.05.04.18; Mon, 27 Mar 2023 05:04:48 -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=@linuxfoundation.org header.s=korg header.b=qqjwaYgy; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232582AbjC0MBR (ORCPT + 99 others); Mon, 27 Mar 2023 08:01:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232591AbjC0MBP (ORCPT ); Mon, 27 Mar 2023 08:01:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C79F735BB; Mon, 27 Mar 2023 05:01:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 72EC9B81148; Mon, 27 Mar 2023 12:01:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4E2AC433EF; Mon, 27 Mar 2023 12:01:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1679918471; bh=WGc0hjU9EXtgJYoWwCb/QMpZOY1aoZ9G/w6FiV/frqU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qqjwaYgyATxb8Cz0/j+qBqdeHMyfoAaDZRpAmcmwk2Ctl3bx2mfO7KcsRc6VNa4XG UYv4g6LlkcbhkahSK/3UK+7k1FxQaqNZfrU6uYS2vF/2+5s32iNBDgJEAdoZfBCEQs iEVZvOLJsmnAuGmoSkUVi0gxDpUhEsCmedXWcGDE= Date: Mon, 27 Mar 2023 14:01:07 +0200 From: Greg Kroah-Hartman To: Matti Vaittinen Cc: Matti Vaittinen , Brendan Higgins , David Gow , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, Stephen Boyd , Jonathan Cameron , linux-iio@vger.kernel.org Subject: Re: [PATCH v6 3/7] kunit: Add kunit wrappers for (root) device creation Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 On Mon, Mar 27, 2023 at 02:34:02PM +0300, Matti Vaittinen wrote: > A few tests need to have a valid struct device. One such example is > tests which want to be testing devm-managed interfaces. > > Add kunit wrapper for root_device_[un]register(), which create a root > device and also add a kunit managed clean-up routine for the device > destruction upon test exit. I really do not like this as a "root device" is a horrible hack and should only be used if you have to hang other devices off of it and you don't have a real device to tie those devices to. Here you are abusing it and attempting to treat it as a real device, which it is not at all, because: > Special note: In some cases the device reference-count does not reach > zero and devm-unwinding is not done if device is not sitting on a bus. > The root_device_[un]register() are dealing with such devices and thus > this interface may not be usable by all in its current form. More > information can be found from: > https://lore.kernel.org/dri-devel/20221117165311.vovrc7usy4efiytl@houat/ See, not a real device, doesn't follow normal "struct device" rules and lifetimes, don't try to use it for a test as it will only cause problems and you will be forced to work around that in a test. Do the right thing here, create a fake bus and add devices to it. Heck, I'll even write that code if you want it, what's the requirement, something like: struct device *kunit_device_create(struct kunit *test, const char *name); void kunit_device_destroy(struct device *dev); ? Why do you want a "match" function? You don't provide documentation here for it so I have no idea. Anything else needed? > The use of root-devices in the kunit helpers is intended to be an > intermediate solution to allow tests which do not require device to sit > on a bus avoid directly abusing the root_device_[un]register() while > proper kunit device solution is being worked on. Related discussion can be > found from: > https://lore.kernel.org/lkml/CABVgOSmx3A4Vwos2_8xO-XQrQAw5gvY0nc5zLpLmcJ7FtA-dTQ@mail.gmail.com/ Again, no, please let's not get this wrong now and say "we will fix this later" as that's not how kernel development should work... thanks, greg k-h