From patchwork Tue Sep 15 16:46:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Duncan X-Patchwork-Id: 7188531 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 5CCF19F32B for ; Tue, 15 Sep 2015 16:56:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 904EB2070F for ; Tue, 15 Sep 2015 16:56:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A361020695 for ; Tue, 15 Sep 2015 16:56:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752957AbbIOQrq (ORCPT ); Tue, 15 Sep 2015 12:47:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:52813 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752272AbbIOQrp (ORCPT ); Tue, 15 Sep 2015 12:47:45 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 28913AD21; Tue, 15 Sep 2015 16:47:42 +0000 (UTC) Received: by worklaptop.gonzoleeman.net (Postfix, from userid 1000) id 775D640C55; Tue, 15 Sep 2015 09:47:36 -0700 (PDT) From: Lee Duncan To: , Cc: Hannes Reinecke , Johannes Thumshirn , Christoph Hellwig , Lee Duncan Subject: [PATCH 04/17] Update the ch driver to use idr helper functions. Date: Tue, 15 Sep 2015 09:46:04 -0700 Message-Id: <1a6d624b850fa7543c9c1fcca647ddb654954296.1442263512.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);