From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755722AbcECNqq (ORCPT ); Tue, 3 May 2016 09:46:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:35254 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751264AbcECNqp (ORCPT ); Tue, 3 May 2016 09:46:45 -0400 Subject: Re: [PATCH] block: initialize hd_stuct's reference before assigning it To: Johannes Thumshirn , Jens Axboe References: <1462282683-17664-1-git-send-email-jthumshirn@suse.de> Cc: linux-block@vger.kernel.org, Linux Kernel Mailinglist , Alexander Graf From: Hannes Reinecke Message-ID: <5728ABC2.5060905@suse.de> Date: Tue, 3 May 2016 15:46:42 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <1462282683-17664-1-git-send-email-jthumshirn@suse.de> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/03/2016 03:38 PM, Johannes Thumshirn wrote: > Inititialize the hd_struct's perpcu reference before assigning the hd_struct > to the partition table list. > > This fixes a race which could be triggered using a simple partition > creation/deletion loop with virtio-blk on aarch64. > > Signed-off-by: Johannes Thumshirn > --- > block/partition-generic.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/block/partition-generic.c b/block/partition-generic.c > index 5d87019..aa5b83a 100644 > --- a/block/partition-generic.c > +++ b/block/partition-generic.c > @@ -361,6 +361,10 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno, > goto out_del; > } > > + err = -ENOMEM; > + if (hd_ref_init(p)) > + goto out_free_info; > + > /* everything is up and running, commence */ > rcu_assign_pointer(ptbl->part[partno], p); > > @@ -368,8 +372,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno, > if (!dev_get_uevent_suppress(ddev)) > kobject_uevent(&pdev->kobj, KOBJ_ADD); > > - if (!hd_ref_init(p)) > - return p; > + return p; > > out_free_info: > free_part_info(p); > Suggested-by: Hannes Reinecke Reviewed-by: Hannes Reinecke :-) Cheers, Hannes -- Dr. Hannes Reinecke Teamlead Storage & Networking hare@suse.de +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)