From patchwork Sun Mar 19 08:41:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5p2O5oms6Z+s?= X-Patchwork-Id: 71731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp641246wrt; Sun, 19 Mar 2023 01:51:31 -0700 (PDT) X-Google-Smtp-Source: AK7set8WUrAa+vJj/94iqSvW2wFictaB+OzomOHq6AV8YcHPkaUFstc5D3klLFddGtZC6gsN+I0C X-Received: by 2002:a05:6a20:6982:b0:d4:5ae6:fbaf with SMTP id t2-20020a056a20698200b000d45ae6fbafmr19965006pzk.60.1679215891015; Sun, 19 Mar 2023 01:51:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679215890; cv=pass; d=google.com; s=arc-20160816; b=ZqLYf6KQ5I79qk1a8HqR476QGlXoAx9fOxE64ca8RnkxJ1YXwW1uC2SQ44ZKAg1cUZ 7CChv0tXMeTQIcoCH9W8ZwmWBSmNEatd2UJ01RRAVj/UFxiqjqupXfZliKFF4xL0PuSI xOGDtGTngm7btYx6YdnNgxPsy59XweFlAbIUAvnKI3vCJfHYtUnxHu4XOEfp7FvTBHly rjKsBvE6ZJrHIf2CFz30xf5Dj34qQveRrDWsdZefrpKpt91DKlGj8ArDiqoeMnRMwrwn rjoOeWhid5D25f9Gc22lvItlJZdIcz5M03zCOQ/S9C+3GUMk40YTN7kSIZ9dQ663NVWm 3ncQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=6BZayVBRrs48yzFLcLJlf01NdTuhulQfafIL7TCrlZg=; b=AnxYUZpnUZYkxwdEns+sH4rcfTTMVlUXVaKx5YWyVKvOlBZwV2Ieqs7Rk06GdeDJlj /fdkXAAwEFtxrt6wBAUfpZ/hZGdT908PkIvRR6E0VOkbIhIlldR2Yr9ZdRfTzCjTyQm8 dDf3GfZcBsr9wFK00CAhdEzfnoYqoCCIkmiZki2YHbNIshxmVBze0tCaG0TpRaJXxF3K sEuzmHaVn7MNjaPo2syK9GWC6EhARQfMLZdEXZcQ+QrLQwtWkZ6FdwcwENGJKrbtOubl AiqRkwQW0ED+OyRJyjsWrhEjZWFxTiXrMvaY/BwUAnlO2Ubt+mir4vN034WquoTtqjKQ GDaQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=J6fCEEhR; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bd12-20020a656e0c000000b004fab1ea0112si7700538pgb.528.2023.03.19.01.51.19; Sun, 19 Mar 2023 01:51:30 -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=@vivo.com header.s=selector2 header.b=J6fCEEhR; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229927AbjCSIl4 (ORCPT + 99 others); Sun, 19 Mar 2023 04:41:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbjCSIlx (ORCPT ); Sun, 19 Mar 2023 04:41:53 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2098.outbound.protection.outlook.com [40.107.117.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7253E1042C for ; Sun, 19 Mar 2023 01:41:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DU2H/x/pK1tDKAxdarh5x9R1u2kWGXHPMwwaDmtG19Cet6vbduExN1Y+W+1oQDC6oKpZDLouwctVkb98FF5jFA2QpEAJeUG4XaBhaKfP7qoNKhs7MCqxiU5RxRBmWheHVdsw8HZO1AlRzYHhzG00Av/a5MJDcayhf42jE8yVWZKSfTL1m1C/uWd53DhYBJtvsPdcjhNNkH3CJ5Nm1jDVXmr3HVlVsYFNTCfA7pl7wwwdHqa13sqwNt50JGxZElu0HCw8BqHQlwgihzFPCLLGgGZBhpqzBgxbOAGrmCTS38rtCExBeuYDARa/zek3xbNYngtSraT8fv745aQSBTaAZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6BZayVBRrs48yzFLcLJlf01NdTuhulQfafIL7TCrlZg=; b=hyMI/xlg4ZupwwWff1vUdO7cMxYhj0HJQ1v0Nr0WK5xPmN2eRp/gO2q+Y/M63Li82gDNYKAXM4Chpo7R0GEoZHnUlzugk5IZdxMaZ8KKFBrOcIzfjksa//qXki4QWU7mNnJ/W30wVsXVxFTlcffj29OZ8SgaMjpNds45nTJVnlOHTRVZsdZkhL8oX+ps3LAccInaeMhHceh2UVUXuqFG+R/hHcal8eklOCL/bY+jdhCvekb+5UPCKwC2WEGQ60HZ50ynZusOlWkEiJ4WwD+rQKtQ+q1jL3eTVcGrMkxC8Zp7tGAPCDTRwPsGTQTJrGZxbr6YI7FI/F8KKPLFTZ7Eog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6BZayVBRrs48yzFLcLJlf01NdTuhulQfafIL7TCrlZg=; b=J6fCEEhREDEm6yx4auOrL5Oi2pxqYzHPeqIonFpKyYdRcn+fMrX0tTBWDcqZcGSQKF1J2u4v5PhvRJ9EAuxRiAcfjYauljTBgIMOf5ELDOJLLay18wEVvvPBKkTDC6Q8wucJTdgZy2vfRYxCIVs5c3ySiadKp0iNOsAzIMTbkDvHsugUvvWCvD7ucyHooybN4//hg7P2sXZv5xB74HdgykpYaGop710o1yvu0Kof0OP39JRpA9rHEGGcNBZqe470g2P08pDAYDxWMARvUTqhwcrgzzhJDaijdcxNcfXZelDkIhwOeOWilDGScsnbCCdDiki10E25SQR665GtHtNx5A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by SEYPR06MB5350.apcprd06.prod.outlook.com (2603:1096:101:6a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Sun, 19 Mar 2023 08:41:46 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::daf6:5ebb:a93f:1869]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::daf6:5ebb:a93f:1869%9]) with mapi id 15.20.6178.037; Sun, 19 Mar 2023 08:41:45 +0000 From: Yangtao Li To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Yangtao Li , linux-kernel@vger.kernel.org Subject: [PATCH v2 01/10] kobject: introduce kobject_del_and_put() Date: Sun, 19 Mar 2023 16:41:24 +0800 Message-Id: <20230319084134.11804-1-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: SI2PR02CA0033.apcprd02.prod.outlook.com (2603:1096:4:195::20) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|SEYPR06MB5350:EE_ X-MS-Office365-Filtering-Correlation-Id: 4784f520-a2fb-4f90-2748-08db2855c5b2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yT681Q1ECEdddz2imbxelwRiCzmu4liK0+RzRVzRt4Yjzx+CWL+C+4fRBtGGryYDGL7y7Xlcak0o9xNHd5yE+PGqy2MfIrffdKNiZXbKuUyKpR4r18ejJHl1NrzPaoUOpdW37xF0mMlfWKLFwziONV+PBeQEQW7UVX2YxGISmqP58yhdWsQnt6u92W006EglGUlmbgKlqKYpVgLecJRS0Av66n0tQEMWCEyGlKqjUqOW1iPAWhuXQiDgQQmj149X4BdrQvVVosnaOCVg38/NZkip2ce+buG1ElIbcJTlHj2Ssl1oboH3notb+FThb00CWhpEsVB+0DdvmDcLh/vzyzFR1BrO7WUHXst/g0VPhvDakgXM0zahJR9npqVbrR9d3aG5hwfgYjtxfTGZSVem6w+Im2Bq6Ckd0arnMS4oM/v5ZT5Zza5GgA6ygds5lL7Yy2qnPdngrKxDhXPCE8BaUUvC6fdtZ0YoKVJE2MBskJrp/bOXeRJEwraD2YkcLxeHNwt7wcUteIaGgfksIj7BOsqmduJ7hbdRnc/zSU57/2bro65qkvLXXwAV7NfQzhgEuOzFbUt1RoAklWnK75qKYH6HPRaSjaAVCy0aXomaejESRMcNOGSSZ43dw1V7eC2uiAONN+VpxFHUpXZYL1P254ZPk8a29QfYKjq1L+bbCfDsqBNqZqxd8jTKw4hZSMjKQiKqyGRf4PffhQrnkfB6jQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5269.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(366004)(376002)(346002)(396003)(136003)(451199018)(86362001)(36756003)(52116002)(83380400001)(316002)(8676002)(4326008)(66476007)(66946007)(66556008)(110136005)(478600001)(186003)(26005)(1076003)(6512007)(6506007)(2616005)(6486002)(6666004)(38100700002)(38350700002)(8936002)(5660300002)(41300700001)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: foQBbTFJkWNU48/cfYpBch9nq5V0wsvrLbBos0a5hIAwKmqFeSCRYJrAS36kO1BDR4MolRoZ+I1o5MV0sRyTFqmgGYabM90MhSzFeyWckabqciLAzIjxYi4syS92sX433Qj6wbi3ewp7RVNAreywkQcqRJec3/XssVIH4RiIs0yfc3lA8X+YlfGNCoCBdrvqMyhzA4VIiZl6I+tHG4lZdvRT8Izc3Xy0S/4YmLiHsjewmWWC6HEWXrjvHLVB3OWooWMCrz3BnyeA2c5HnaguNa1jeGc8dA/9KOhsf/IFEpE20dmVaMzgpCwhuvTg7TrYXaAfmvp0uQcKv1BqAs2z+nK4HeME2cWOlQCCIEB7K8M5mgXFovU+BBESiNIwhYPQrbPu+ZfYqFdKXTiKFCK9yFHuV2XVTm7hIYI5rNwI9Kwxpc2FsO2smp1GVD5NgtL6Jq+Hkn3zdoz04WXE+71dNLBwXamaQkHBQJV+WKdWuTiEVMgxk2cNk9iSd494V7SMHXXMTNqiW4aoD8kPZ03H4DfQW6Mdgkzs7oR59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-Network-Message-Id: 4784f520-a2fb-4f90-2748-08db2855c5b2 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2023 08:41:45.8425 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Rsd9711XFmkUTxfOXx7JsI2q8O0CdP2zqVv3uF0cGo62YwgBuLCS30wLCbKAnbG4wQlPbMrAlFrB2/H/Oal3Gw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB5350 X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL,SPF_HELO_PASS,SPF_PASS autolearn=no 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760785482143863532?= X-GMAIL-MSGID: =?utf-8?q?1760785482143863532?= There are plenty of using kobject_del() and kobject_put() together in the kernel tree. This patch wraps these two calls in a single helper. Signed-off-by: Yangtao Li --- v2: -add kobject_del_and_put() users include/linux/kobject.h | 1 + lib/kobject.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/linux/kobject.h b/include/linux/kobject.h index bdab370a24f4..782d4bd119f8 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -111,6 +111,7 @@ extern struct kobject *kobject_get(struct kobject *kobj); extern struct kobject * __must_check kobject_get_unless_zero( struct kobject *kobj); extern void kobject_put(struct kobject *kobj); +extern void kobject_del_and_put(struct kobject *kobj); extern const void *kobject_namespace(const struct kobject *kobj); extern void kobject_get_ownership(const struct kobject *kobj, diff --git a/lib/kobject.c b/lib/kobject.c index 6e2f0bee3560..8c0293e37214 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -731,6 +731,20 @@ void kobject_put(struct kobject *kobj) } EXPORT_SYMBOL(kobject_put); +/** + * kobject_del_and_put() - Delete kobject. + * @kobj: object. + * + * Unlink kobject from hierarchy and decrement the refcount. + * If refcount is 0, call kobject_cleanup(). + */ +void kobject_del_and_put(struct kobject *kobj) +{ + kobject_del(kobj); + kobject_put(kobj); +} +EXPORT_SYMBOL_GPL(kobject_del_and_put); + static void dynamic_kobj_release(struct kobject *kobj) { pr_debug("kobject: (%p): %s\n", kobj, __func__); @@ -874,8 +888,7 @@ void kset_unregister(struct kset *k) { if (!k) return; - kobject_del(&k->kobj); - kobject_put(&k->kobj); + kobject_del_and_put(&k->kobj); } EXPORT_SYMBOL(kset_unregister);