From patchwork Wed Sep 16 17:50:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Duncan X-Patchwork-Id: 7197891 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 772A89F54C for ; Wed, 16 Sep 2015 17:51:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AFA00207CB for ; Wed, 16 Sep 2015 17:51:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B3CC2208AF for ; Wed, 16 Sep 2015 17:51:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754219AbbIPRvQ (ORCPT ); Wed, 16 Sep 2015 13:51:16 -0400 Received: from mx2.suse.de ([195.135.220.15]:51402 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754171AbbIPRvO (ORCPT ); Wed, 16 Sep 2015 13:51:14 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 83944ADAC; Wed, 16 Sep 2015 17:51:13 +0000 (UTC) Received: by worklaptop.gonzoleeman.net (Postfix, from userid 1000) id 1FF0040C79; Wed, 16 Sep 2015 10:51:07 -0700 (PDT) From: Lee Duncan To: linux-scsi@vger.kernel.org, James.Bottomley@HansenPartnership.com Cc: linux-kernel@vger.kernel.org, hare@suse.com, jthumshirn@suse.de, hch@infradead.org, Lee Duncan Subject: [PATCH 04/17] Update the ch driver to use idr helper functions. Date: Wed, 16 Sep 2015 10:50:22 -0700 Message-Id: <1a6d624b850fa7543c9c1fcca647ddb654954296.1442263513.git.lduncan@suse.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Note: when allocating an index, in the error case, where the just-allocated index has to be released, the required locking around the index removal was not present, so this conversion has the side effect of adding locking for that error condition. This should close a possible race condition that could have resulted in duplicate index allocation. Signed-off-by: Lee Duncan --- drivers/scsi/ch.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c index dad959fcf6d8..2edf1f8883f9 100644 --- a/drivers/scsi/ch.c +++ b/drivers/scsi/ch.c @@ -909,12 +909,8 @@ static int ch_probe(struct device *dev) if (NULL == ch) return -ENOMEM; - idr_preload(GFP_KERNEL); - spin_lock(&ch_index_lock); - ret = idr_alloc(&ch_index_idr, ch, 0, CH_MAX_DEVS + 1, GFP_NOWAIT); - spin_unlock(&ch_index_lock); - idr_preload_end(); - + ret = idr_get_index_in_range(&ch_index_idr, &ch_index_lock, ch, + 0, CH_MAX_DEVS + 1); if (ret < 0) { if (ret == -ENOSPC) ret = -ENODEV; @@ -945,7 +941,7 @@ static int ch_probe(struct device *dev) return 0; remove_idr: - idr_remove(&ch_index_idr, ch->minor); + idr_put_index(&ch_index_idr, &ch_index_lock, ch->minor); free_ch: kfree(ch); return ret; @@ -955,9 +951,7 @@ static int ch_remove(struct device *dev) { scsi_changer *ch = dev_get_drvdata(dev); - spin_lock(&ch_index_lock); - idr_remove(&ch_index_idr, ch->minor); - spin_unlock(&ch_index_lock); + idr_put_index(&ch_index_idr, &ch_index_lock, ch->minor); device_destroy(ch_sysfs_class, MKDEV(SCSI_CHANGER_MAJOR,ch->minor)); kfree(ch->dt);