Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3312880ybb; Tue, 31 Mar 2020 02:42:33 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsbp8j4hERTYWh4rxED06LPl2N5g3XgOp7o8tINbfzuyEjkuYbgsPGPbAiUmhj+SOUKkUQJ X-Received: by 2002:aca:de42:: with SMTP id v63mr1352769oig.99.1585647753541; Tue, 31 Mar 2020 02:42:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585647753; cv=none; d=google.com; s=arc-20160816; b=Z6r7A11aGKgKVPBeMgtqSWhJLhoVgGw8ZfdcRguOPQWwhoSBtRUUdPgVatGYjLQSLK 4jpmESaMDw3/+xXbcm89+fIOhZ6hP26wpc0HfOCY1qyQObBuTfJFo0B0s6tleimwD6iw t62+3+lw1jLethJ30wWe7cl1efxHLnLIONuJYFAGSg+eQ2B7NWBKIGq/8vAbVJkyM3vW w5Ygwd9gGv8i+5UMfyTcfIv6ikl92kd4Z2FIad6DcI6KFCBtPvBqmykjCqw+MRms9Vvn d2I/E29cpFWd/OBqtj7+Exqrix6iGTzeWDu3VhRVem2bQfM2gp8S9g5cHbQnfvbGwhkc Mq8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=VJNkCFRnazt3YHUhnvm9U27h6AlyelC4B27ZdZ7yi/k=; b=dTPpirXEOZ/+sbF7HRmwmIBqxJL6V+yrMGFV6OabrjzMJBFI5VVbKp0O7UGRS7vvQi /2ynnpIuUKt4P4jWqNN96/8jc1+ElEofxdUn1xVLqA1MY8xDgcrXH0eN8/vqhDlZjrBB C+MOz0tit+q0o9NtsXIwzES/BaAkA7XJ7mi+DJPKU6NRrGLIheRRMOAhLpwEOhtTcDZ8 PW41A/FC9n8GCuo/FvU0FrKqldDtZpJ/BvClIXMpV1Fo0gSALGfjmq9vRQYPkLuVV+Tq 5g0E33nmOWIRVLX4ZaBwnT5mA3DALZddUla9+hZkysGGn+AxyzE2oteOX975TsfW8p1+ Rlfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z24si6868295ool.40.2020.03.31.02.42.17; Tue, 31 Mar 2020 02:42:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730500AbgCaJli (ORCPT + 99 others); Tue, 31 Mar 2020 05:41:38 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:34093 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730455AbgCaJlh (ORCPT ); Tue, 31 Mar 2020 05:41:37 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 02V9f7c6024531; Tue, 31 Mar 2020 11:41:07 +0200 From: Willy Tarreau To: Denis Efremov Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions Date: Tue, 31 Mar 2020 11:40:53 +0200 Message-Id: <20200331094054.24441-23-w@1wt.eu> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20200331094054.24441-1-w@1wt.eu> References: <20200331094054.24441-1-w@1wt.eu> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Both floppy_grab_irq_and_dma() and floppy_release_irq_and_dma() used to iterate on the global variable while setting up or freeing resources. Now that they exclusively rely on functions which take the fdc as an argument, so let's not touch the global one anymore. Signed-off-by: Willy Tarreau --- drivers/block/floppy.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 8850baa3372a..77bb9a5fcd33 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -4854,6 +4854,8 @@ static void floppy_release_regions(int fdc) static int floppy_grab_irq_and_dma(void) { + int fdc; + if (atomic_inc_return(&usage_count) > 1) return 0; @@ -4881,24 +4883,24 @@ static int floppy_grab_irq_and_dma(void) } } - for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) { - if (fdc_state[current_fdc].address != -1) { - if (floppy_request_regions(current_fdc)) + for (fdc = 0; fdc < N_FDC; fdc++) { + if (fdc_state[fdc].address != -1) { + if (floppy_request_regions(fdc)) goto cleanup; } } - for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) { - if (fdc_state[current_fdc].address != -1) { - reset_fdc_info(current_fdc, 1); - fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR); + for (fdc = 0; fdc < N_FDC; fdc++) { + if (fdc_state[fdc].address != -1) { + reset_fdc_info(fdc, 1); + fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR); } } - current_fdc = 0; + set_dor(0, ~0, 8); /* avoid immediate interrupt */ - for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) - if (fdc_state[current_fdc].address != -1) - fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR); + for (fdc = 0; fdc < N_FDC; fdc++) + if (fdc_state[fdc].address != -1) + fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR); /* * The driver will try and free resources and relies on us * to know if they were allocated or not. @@ -4909,15 +4911,16 @@ static int floppy_grab_irq_and_dma(void) cleanup: fd_free_irq(); fd_free_dma(); - while (--current_fdc >= 0) - floppy_release_regions(current_fdc); + while (--fdc >= 0) + floppy_release_regions(fdc); + current_fdc = 0; atomic_dec(&usage_count); return -1; } static void floppy_release_irq_and_dma(void) { - int old_fdc; + int fdc; #ifndef __sparc__ int drive; #endif @@ -4958,11 +4961,9 @@ static void floppy_release_irq_and_dma(void) pr_info("auxiliary floppy timer still active\n"); if (work_pending(&floppy_work)) pr_info("work still pending\n"); - old_fdc = current_fdc; - for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) - if (fdc_state[current_fdc].address != -1) - floppy_release_regions(current_fdc); - current_fdc = old_fdc; + for (fdc = 0; fdc < N_FDC; fdc++) + if (fdc_state[fdc].address != -1) + floppy_release_regions(fdc); } #ifdef MODULE -- 2.20.1