From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24AB6C07E95 for ; Wed, 7 Jul 2021 09:48:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0375961CBA for ; Wed, 7 Jul 2021 09:48:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231361AbhGGJvS (ORCPT ); Wed, 7 Jul 2021 05:51:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230498AbhGGJvQ (ORCPT ); Wed, 7 Jul 2021 05:51:16 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 645DDC061574; Wed, 7 Jul 2021 02:48:36 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id v7so1660882pgl.2; Wed, 07 Jul 2021 02:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nDphwP7rk7MVmmwi41RmQwruvzgJtyrk5UC8vBfmCnU=; b=HAwqV7SRwg6Bmoo+IUskz5DjJH8OArmVvNbXrAsMJFs1WKQPXL4k8BMKwnvr8tsADx V+Kss4NWm4EsIyxBLRXjn20jxwQac+LwPilRbQCebnzRO9fHHDPUfsOLIyd1aflsfhrY eZRG9VycHCBnh9ASsKcssnV5YuYaHu7v5YQ9E0AL7uLvzx/E3KFR4DhrMCg7dAm/GuNX XSFQYJF47N/D9cKiDGVJEzWca8GP3OU8YxzWzS9DKK9tR7P0gc+uvIeEXzxjB/J1O3W5 J7Zj9lYBjV0FGeERQcv0rBKI2/E6tv32w3NdOFSSr+kxAI7duSNB5bg/mAKgPGnfaSjh LJYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nDphwP7rk7MVmmwi41RmQwruvzgJtyrk5UC8vBfmCnU=; b=D8ko6DHvKA8GFJm0J9HTwneW6BZu+T3/nDXWaNWepbhRX3bD5iUmVgoAJljaNPB55p 4o6vHsExfP555awOXzsYTLXwVoZVO7t43OzDAC6U9wJnsBYfWhQBrHwkzeXeDmSCEZu1 ghyOhdKqwSJmbMaTaI8R82FEHVNyKGGQnCWLGyncGV3XGEpyGb7J3nNfNqcqdEgNQJfM DqwnYjYcdxwMoUE3eYowW28oWa8gE+m1r5Md9Cyng851H6g55JfQsm68FPNcSz9EWUkP bNpym7A5LB2Wj8u58XVSByAUtdlUAm3sordO+zaMO8Z/gXyv7TxhJ4xFAZXOq4QrnSi4 SyOg== X-Gm-Message-State: AOAM5300twUNODA/65DuC0hibA/tDtYwst2ztJ0yLDGmfbcmoozqes3T 5jg2u6jDztn0aU1G+mUvUr97JsKEf1I= X-Google-Smtp-Source: ABdhPJwfBIm//0vrmwiLiPS+54Mmlpi6N+akqfKIqHiRb/aTPnQA4/MVR19oI8H7s/cNwoVt3/1o8g== X-Received: by 2002:a65:62d8:: with SMTP id m24mr25729228pgv.150.1625651315958; Wed, 07 Jul 2021 02:48:35 -0700 (PDT) Received: from carrot.localdomain (i60-35-90-140.s42.a014.ap.plala.or.jp. [60.35.90.140]) by smtp.gmail.com with ESMTPSA id gd19sm80137pjb.38.2021.07.07.02.48.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jul 2021 02:48:34 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs , LKML Subject: [PATCH 2/6] nilfs2: fix NULL pointer in nilfs_##name##_attr_release Date: Wed, 7 Jul 2021 18:48:22 +0900 Message-Id: <1625651306-10829-3-git-send-email-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1625651306-10829-1-git-send-email-konishi.ryusuke@gmail.com> References: <1625651306-10829-1-git-send-email-konishi.ryusuke@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nanyong Sun In nilfs_##name##_attr_release, kobj->parent should not be referenced because it is a NULL pointer. The release() method of kobject is always called in kobject_put(kobj), in the implementation of kobject_put(), the kobj->parent will be assigned as NULL before call the release() method. So just use kobj to get the subgroups, which is more efficient and can fix a NULL pointer reference problem. Link: https://lkml.kernel.org/r/20210629022556.3985106-3-sunnanyong@huawei.com Signed-off-by: Nanyong Sun Signed-off-by: Ryusuke Konishi --- fs/nilfs2/sysfs.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c index b6a48492fed2..43f660beb9b4 100644 --- a/fs/nilfs2/sysfs.c +++ b/fs/nilfs2/sysfs.c @@ -64,11 +64,9 @@ #define NILFS_DEV_INT_GROUP_TYPE(name, parent_name) \ static void nilfs_##name##_attr_release(struct kobject *kobj) \ { \ - struct nilfs_sysfs_##parent_name##_subgroups *subgroups; \ - struct the_nilfs *nilfs = container_of(kobj->parent, \ - struct the_nilfs, \ - ns_##parent_name##_kobj); \ - subgroups = nilfs->ns_##parent_name##_subgroups; \ + struct nilfs_sysfs_##parent_name##_subgroups *subgroups = container_of(kobj, \ + struct nilfs_sysfs_##parent_name##_subgroups, \ + sg_##name##_kobj); \ complete(&subgroups->sg_##name##_kobj_unregister); \ } \ static struct kobj_type nilfs_##name##_ktype = { \ -- 1.8.3.1