From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) by dpdk.org (Postfix) with ESMTP id A74AE37B2 for ; Thu, 22 Sep 2016 01:44:34 +0200 (CEST) Received: by mail-pa0-f49.google.com with SMTP id hm5so22951442pac.0 for ; Wed, 21 Sep 2016 16:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WKp1kGo420xEFECIvA3p0KBlU4CMCshBaHZNQpYPncc=; b=IKpTE3uiV9wGeGQzEmKJQhxUhCKc/1U94kvze39r0ME1pJ3ezACNjaTnT9Y5Yk+gfA cUTPcsiIhX4j0w49r+evlfI+08ut/BcDUZ86/2fRb/vi5cfLbt7q5fvNE7K6Ch3jIYav KsP8ayOzOw0P1nApfvEDAtG5e+NIgYJyOjsgh8u+oQDhZCrA32fCaqpiGEqWynUY1tFC o7hrW1SsPgCzSKfNjon6L4rBLYMJoGhViN+/l8pKMKO/5DhklamIofKr8oJbrzQEqQkN ZWMScXzjMdKjIakxSnDNaAMXb0QfuoBzAz1BiOc44GkuL07sykZAxX6LnkZFp5TcbQmO ioCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WKp1kGo420xEFECIvA3p0KBlU4CMCshBaHZNQpYPncc=; b=ckAdYbDb22qzQV39MaMqFD7J4i3VcsPYnoRwvxkytdg1vWENYHoPAJ28M41+aYyRsH /8bxHzH3gWwxja0zxSFS2mYnGXj5nzodk5I6hCbhZfNQN63zrobco6czc4JG53+lNEmh xfJgSKE9GFrFkIbrC8mfycm7CPcmNEFXPDJ2Ou2otoRisSzr+DKeHVKJ0HrcTw89Hm1q 6AZMfbR5qMTudHKboM163foY5bPhPb5arZqjgt1oeRWGUSxJLLQb/nxUPsCjSfUKU2KB CgcfQug+JLiImYDCz3i63L7A6tMVNoLHYBM5mz6lEQPna3izEgSwUQcYP56Mgg8rJnDE NUTA== X-Gm-Message-State: AE9vXwPZbA0X8xRXyIkfdfb/Yspu9a1+iFysjNw/Ou1KSqNU9nhun+KqA1c8/Lt/7On+bA== X-Received: by 10.66.254.170 with SMTP id aj10mr69302524pad.124.1474501474014; Wed, 21 Sep 2016 16:44:34 -0700 (PDT) Received: from xeon-e3 (static-50-53-69-251.bvtn.or.frontiernet.net. [50.53.69.251]) by smtp.gmail.com with ESMTPSA id k77sm365879pfj.65.2016.09.21.16.44.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Sep 2016 16:44:33 -0700 (PDT) Date: Wed, 21 Sep 2016 16:44:44 -0700 From: Stephen Hemminger To: Ferruh Yigit Cc: Vladyslav Buslov , "dev@dpdk.org" Message-ID: <20160921164444.6ea1030e@xeon-e3> In-Reply-To: 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> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Sep 2016 23:44:35 -0000 On Wed, 21 Sep 2016 19:23:47 +0100 Ferruh Yigit wrote: > 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 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 Also any additional fields in knet will be set, avoiding any present or future uninitialized memory bugs.