From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ferruh.yigit@intel.com>
Received: from mga09.intel.com (mga09.intel.com [134.134.136.24])
 by dpdk.org (Postfix) with ESMTP id C39672952
 for <dev@dpdk.org>; Wed, 21 Sep 2016 20:23:49 +0200 (CEST)
Received: from orsmga001.jf.intel.com ([10.7.209.18])
 by orsmga102.jf.intel.com with ESMTP; 21 Sep 2016 11:23:49 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.30,374,1470726000"; d="scan'208";a="1034323690"
Received: from fyigit-mobl1.ger.corp.intel.com (HELO [10.237.220.98])
 ([10.237.220.98])
 by orsmga001.jf.intel.com with ESMTP; 21 Sep 2016 11:23:47 -0700
To: Vladyslav Buslov <Vladyslav.Buslov@harmonicinc.com>,
 Stephen Hemminger <stephen@networkplumber.org>
References: <20160910135016.6468-2-vladyslav.buslov@harmonicinc.com>
 <20160920181637.26778-1-vladyslav.buslov@harmonicinc.com>
 <20160920113636.38b2ed2a@xeon-e3>
 <366f0b2a-abb6-9fdc-cd12-d79185d32c5e@intel.com>
 <MWHPR11MB13603BE178683944EE80D7999DF60@MWHPR11MB1360.namprd11.prod.outlook.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
From: Ferruh Yigit <ferruh.yigit@intel.com>
Message-ID: <c66c9cfe-2702-a3a0-94b3-e3232030c55d@intel.com>
Date: Wed, 21 Sep 2016 19:23:47 +0100
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101
 Thunderbird/45.3.0
MIME-Version: 1.0
In-Reply-To: <MWHPR11MB13603BE178683944EE80D7999DF60@MWHPR11MB1360.namprd11.prod.outlook.com>
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit
Subject: Re: [dpdk-dev] [PATCH] kni: add support for core_id param in single
 threaded mode
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 21 Sep 2016 18:23:50 -0000

On 9/21/2016 6:15 PM, Vladyslav Buslov wrote:
>> On 9/20/2016 7:36 PM, Stephen Hemminger wrote:
>>> On Tue, 20 Sep 2016 21:16:37 +0300
>>> Vladyslav Buslov <vladyslav.buslov@harmonicinc.com> wrote:
>>>
>>>> @@ -123,6 +125,9 @@ static int __net_init kni_init_net(struct net *net)
>>>>  	/* Clear the bit of device in use */
>>>>  	clear_bit(KNI_DEV_IN_USE_BIT_NUM, &knet->device_in_use);
>>>>
>>>> +	mutex_init(&knet->kni_kthread_lock);
>>>> +	knet->kni_kthread = NULL;
>>>> +
>>>
>>> Why not just use kzalloc() here? You would still need to init the
>>> mutex etc, but it would be safer.
>>>
>>
>> Hi Vladyslav,
>>
>> This is good suggestion, if you send a new version for this update, please
>> keep my Ack.
>>
>> Thanks,
>> ferruh
> 
> Hi Ferruh, Stephen,
> 
> Could you please elaborate on using kzalloc for this code.
> Currently kni_thread_lock is value member of kni_net structure and never explicitly allocated or deallocated.
> Kni_kthread is pointer member of kni_net and is implicitly created and destroyed by kthread_run, kthread_stop functions.
> Which one of those do you suggest to allocate with kzalloc() and how would it improve safety?
> 

Currently:

kni_init_net() {
    knet = kmalloc(..);
    ..
    mutex_init(..);
    knet->kni_thread = NULL;
}

If you allocate knet via kzalloc(), no need to assign NULL to
kni_thread. Also this is safer because any uninitialized knet field will
be zero instead of random value.

This is what I understood at least J

Thanks,
ferruh