Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp350860ybm; Fri, 29 May 2020 01:35:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVWmS05+yf4B9q30am++jf147p9aHwURu5PAUKd8OfucQPVQdTY1VNW5MkhC9zemmskt4X X-Received: by 2002:a05:6402:2216:: with SMTP id cq22mr7182183edb.167.1590741323479; Fri, 29 May 2020 01:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590741323; cv=none; d=google.com; s=arc-20160816; b=ixFiWbYXiFmWGabDWbUeKSNAn7YSwD96tkx5W0TxAloxf7EEYclyrco2TVHSGcm5PG 1m1cXL67O06u57S5zNUhWVnkA/cHM3uow0oy4hPDnANAXVo8SVOLKN3lodRDyV92TMt0 chaVD8Jbf5xmJG3ZLlm3hWVWgJxR8olwgmUjgP9MUEkVdSATvONNn254YeWTrrqFXtRR LxpK46SXeDh2ZUWqNqArdyRcXxuNVCvSP3Yuu/BWN1udynCIgI1TDVaNq3lVOXJaCWEE HkkYklwnqkXevqPnc7vDesO1ax/Hr+V5HzVdgbHlg2RIrMY3JM4DW2r29pxQL4BlNxZI unEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=6X7x8AKNeLqCU2/xB/5df9zNrOv1QdvBOaDsbFiBpUA=; b=SEw1Xyzz0FP+3Y/GpnMLHeEfSDC4U6T5CKExZ19OgxB4x4bmbCZcAD+yNIGJqsJMNA lSr/6EayixrunmAIbw9m35wnKPoTRtPRzxF89GIM1eJIWNp9kugj/6DE7uHPeZfhDQYr qYPUmhUbUH3TpR77pps53l90E2vzG3MaOb+zd0XiBOFYsJRrJWLdavmAgMx/M2+s9PTp 15voYx6kfGcabV7hwKYXwTw5Z3CP7b+sYJzPltx2Vuvs86LZgX//v7Z1tNCwAOzxCwrt kbNziROcLLZGD8oARfzJ56UAhaPBl1vel8JpCn2PQ9Xd6A/C6I20tnAHX6/K2Dh8NmUz qxBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r2si4773019edq.510.2020.05.29.01.35.00; Fri, 29 May 2020 01:35:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726467AbgE2IdK (ORCPT + 99 others); Fri, 29 May 2020 04:33:10 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5389 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725306AbgE2IdK (ORCPT ); Fri, 29 May 2020 04:33:10 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 4CD208262F231AB18C8A; Fri, 29 May 2020 16:33:08 +0800 (CST) Received: from [127.0.0.1] (10.67.102.197) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Fri, 29 May 2020 16:33:02 +0800 Subject: Re: [PATCH v4 1/4] sysctl: Add register_sysctl_init() interface To: Luis Chamberlain CC: , , , , , , , , , , , , , , , , , , , , , References: <1589859071-25898-1-git-send-email-nixiaoming@huawei.com> <1589859071-25898-2-git-send-email-nixiaoming@huawei.com> <20200529070903.GV11244@42.do-not-panic.com> <3d2d4b2e-db9e-aa91-dd29-e15d24028964@huawei.com> <20200529073646.GW11244@42.do-not-panic.com> From: Xiaoming Ni Message-ID: Date: Fri, 29 May 2020 16:33:01 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: <20200529073646.GW11244@42.do-not-panic.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.102.197] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/5/29 15:36, Luis Chamberlain wrote: > On Fri, May 29, 2020 at 03:27:22PM +0800, Xiaoming Ni wrote: >> On 2020/5/29 15:09, Luis Chamberlain wrote: >>> On Tue, May 19, 2020 at 11:31:08AM +0800, Xiaoming Ni wrote: >>>> --- a/kernel/sysctl.c >>>> +++ b/kernel/sysctl.c >>>> @@ -3358,6 +3358,25 @@ int __init sysctl_init(void) >>>> kmemleak_not_leak(hdr); >>>> return 0; >>>> } >>>> + >>>> +/* >>>> + * The sysctl interface is used to modify the interface value, >>>> + * but the feature interface has default values. Even if register_sysctl fails, >>>> + * the feature body function can also run. At the same time, malloc small >>>> + * fragment of memory during the system initialization phase, almost does >>>> + * not fail. Therefore, the function return is designed as void >>>> + */ >>> >>> Let's use kdoc while at it. Can you convert this to proper kdoc? >>> >> Sorry, I do n’t know the format requirements of Kdoc, can you give me some >> tips for writing? > > Sure, include/net/mac80211.h is a good example. > >>>> +void __init register_sysctl_init(const char *path, struct ctl_table *table, >>>> + const char *table_name) >>>> +{ >>>> + struct ctl_table_header *hdr = register_sysctl(path, table); >>>> + >>>> + if (unlikely(!hdr)) { >>>> + pr_err("failed when register_sysctl %s to %s\n", table_name, path); >>>> + return; >>> >>> table_name is only used for this, however we can easily just make >>> another _register_sysctl_init() helper first, and then use a macro >>> which will concatenate this to something useful if you want to print >>> a string. I see no point in the description for this, specially since >>> the way it was used was not to be descriptive, but instead just a name >>> followed by some underscore and something else. >>> >> Good idea, I will fix and send the patch to you as soon as possible > > No rush :) > >>>> + } >>>> + kmemleak_not_leak(hdr); >>> >>> Is it *wrong* to run kmemleak_not_leak() when hdr was not allocated? >>> If so, can you fix the sysctl __init call itself? >> I don't understand here, do you mean that register_sysctl_init () does not >> need to call kmemleak_not_leak (hdr), or does it mean to add check hdr >> before calling kmemleak_not_leak (hdr) in sysctl_init ()? > > I'm asking that the way you are adding it, you don't run > kmemleak_not_leak(hdr) if the hdr allocation filed. If that is > right then it seems that sysctl_init() might not be doing it > right. > > Can that code be shared somehow? > > Luis void __ref kmemleak_not_leak(const void *ptr) { pr_debug("%s(0x%p)\n", __func__, ptr); if (kmemleak_enabled && ptr && !IS_ERR(ptr)) make_gray_object((unsigned long)ptr); } EXPORT_SYMBOL(kmemleak_not_leak); In the code of kmemleak_not_leak(), it is verified that the pointer is valid, so kmemleak_not_leak (NULL) will not be a problem. At the same time, there is no need to call kmemleak_not_leak() in the failed branch of register_sysctl_init(). Thanks Xiaoming Ni