Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2228073ybi; Mon, 1 Jul 2019 08:21:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHvX5a9vEDlWCCygbS+HKoz6kkDMjvrwHQBly8LVbUa89i4N6Jbiq3i1Lv0z5V6zFI7q67 X-Received: by 2002:a17:90a:9201:: with SMTP id m1mr31990260pjo.38.1561994491764; Mon, 01 Jul 2019 08:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561994491; cv=none; d=google.com; s=arc-20160816; b=rXVW3ygwSVsezFWio1CUQMf9cBmcGOv6g8ZC93tSilI0DNqVxLeGrWE2hya9VDVfVQ dmUnakon5J2lUFOU898TSUah/wh2amcBPsNUIvQGM3cG6YIsrEg7uFsZe57OfVf1LQQD 7iF1P5/Caq8Z8ZRaLiAkDRYI6ADYdRHGefD0jHjqrJcBh0eFMWZ6w0f8VRFQWad3TdGp 1s5SP+qgs2PNdf0JvlS/Lsy2VfvZcPg3MmqCIeEwpg3Oq6ksGNDWqKAPrO8diqZ3UnF2 rWBFpH8UN6sq5nKyLgWsdL07Ki08bnEr35BGL0+1qruRWNBnvNEpMmtWY/WXAdnuwUXl aQmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=BLLoWARicjEqsLddNpd8/X3br4Bdb2FnRqNO9+/07vg=; b=ozIBwZlEEb2wZ3bo6aaFF7eH7+qpLJgQBWBYFUnbM+S0l1IBAjW6orB0H7lcxlw6QK kml0zhJ9aDC2+jEkNXkvv7I/YKEE/HvRbFaYFOHpiqJzk9g6ndMnNlA4/vc7dNlwfyQF 20X/nOnqI702XsEkmkPY8h+nMq766JdOUvgDwbzDbMnmpaZSGqjH8z3KCPC8oP13H0fg ebHy5Hk7I+dx1RCujWlK70McgN0wO2SGuSVsKQ1hg2p0aQPATGL/FuCyqW4WuE5MfrRw G0ONjuytKeC8BZhmDli0SzSCODjMpEfvtrZYyl//sVtkQAEWEsqYtRSt3FqFiuzsDon+ nb2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EtFpnG8a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g64si10196783pgc.188.2019.07.01.08.21.16; Mon, 01 Jul 2019 08:21:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EtFpnG8a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729231AbfGAN4G (ORCPT + 99 others); Mon, 1 Jul 2019 09:56:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:55056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727736AbfGAN4G (ORCPT ); Mon, 1 Jul 2019 09:56:06 -0400 Received: from linux-8ccs (ip5f5ade8b.dynamic.kabel-deutschland.de [95.90.222.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 427A121721; Mon, 1 Jul 2019 13:56:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561989365; bh=xHYHwRu047LRNEZ0hfMwddr1wPSrP4HvmOSYmeKOh4k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EtFpnG8aR9TUgbf3xWCGa+vcjbnRi9F7wLPxpliR0Uykt9ylLqESGePaDuWpziwMo 1QCuzZ//4Ky5kK6uFgas+Fiu+sY8JZzp2VP69nSJHNfGIzXuH1dhhWdwlXPi7UGdSU 8zlznE8M173BcsQ2phPhvWoUG6q/7wwLC2tBl4Ss= Date: Mon, 1 Jul 2019 15:55:57 +0200 From: Jessica Yu To: Zhiqiang Liu Cc: rusty@rustcorp.com.au, kay.sievers@vrfy.org, clabbe.montjoie@gmail.com, linux-kernel@vger.kernel.org, "wangxiaogang (F)" , "Zhoukang (A)" , Mingfangsen Subject: Re: [PATCH] module: add usage links when calling ref_module func Message-ID: <20190701135556.GA25484@linux-8ccs> References: <8d7aa8b1-73a2-db7a-82c8-06917eddf235@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <8d7aa8b1-73a2-db7a-82c8-06917eddf235@huawei.com> X-OS: Linux linux-8ccs 5.1.0-rc1-lp150.12.28-default+ x86_64 User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +++ Zhiqiang Liu [28/06/19 20:32 +0800]: >From: Zhiqiang Liu > >Problem: Users can call ref_module func in their modules to construct >relationships with other modules. However, the holders >'/sys/module//holders' of the target module donot include >the users` module. So lsmod command misses detailed info of 'Used by'. > >When load module, the process is given as follows, >load_module() > -> mod_sysfs_setup() > -> add_usage_links > -> do_init_module > -> mod->init() > >add_usage_links func creates holders of target modules linking to >this module. If ref_module is called in mod->init() func, the usage >links cannot be added. > >Here, we will add usage link of a to b's holder_dir. > >Fixes: 9bea7f239 ("module: fix bne2 "gave up waiting for init of module libcrc32c") I think we can drop this tag; it doesn't fix a bug specifically introduced by that particular commit. >Signed-off-by: Zhiqiang Liu >--- > kernel/module.c | 5 +++++ > 1 file changed, 5 insertions(+) > >diff --git a/kernel/module.c b/kernel/module.c >index 80c7c09584cf..11c6aff37b1f 100644 >--- a/kernel/module.c >+++ b/kernel/module.c >@@ -871,6 +871,11 @@ int ref_module(struct module *a, struct module *b) > module_put(b); > return err; > } >+ >+ err = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); >+ if (err) >+ return err; We need to fix the error handling here - the module_use struct allocated in the call to add_module_usage() needs to be freed (you could just modify add_module_usage() to return the use pointer so that it's easier to free from within ref_module()), module_put() needs to be called, and the use struct should be removed from its respective lists (see module_unload_free()). Thanks, Jessica