Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp2098819rwj; Sat, 24 Dec 2022 08:38:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXu2Y+UM/EUD+RUP+IHrktdkB38mivK/Onzov0HLdXSjlKe0AgaZfROvygvdYKkVn/QqGBlk X-Received: by 2002:a05:6402:1f12:b0:46c:a1f7:d9c5 with SMTP id b18-20020a0564021f1200b0046ca1f7d9c5mr12264007edb.38.1671899898889; Sat, 24 Dec 2022 08:38:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671899898; cv=none; d=google.com; s=arc-20160816; b=JnDm3zDDDFxMyN2pRaz/D97qEzJ9UE+bHGuK/5EbrYRLlCIzliwY+Q1QXrUOICOiL/ i29pySgLITcbmJ2kA4MQvugn/nZvd2yLBQE7RTE4LyLja6O9yCUoZwutD8caPXA8/uNf itnlsmevpvVYH/Rm6rrxkre1dTqOm5lQ2ezH0aGj3ELVwA6iM5x3s+L7GTV1bJvPeC/J h1Y5KY/TgqICRsbjT18GqjguyUtG8XjxZbyMwTaT+ogtCoiZuAGgHEOlYhFnceIwgpnx gE7CjJxO6B3IN8tvmN1dbca1ERZJUnOGZxKkgjvUX4I8Qt/t3rtXPUr8qk/d1Tfgbcd6 BOsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9SGPV5x0O0HFpoHdnBS8U8scQ6sfEaHibETRS6fZA+Y=; b=Js6FS+j+9iC3QQmcfgh4hDBvae3mbTbhmzl1+JSNB7MUyJ+DYKuJID73QScBeX0j3R gqdzV3O3iCM2U/22O1p3tOUZvvjYYXkb6GIh+yZaHqLGV9aF/dtqjEuxbYe6jokMogs1 ol6965Wu1ZMSPtH/okFLc4eNLUQJfSc22Hb05+H/tWN2VhivFJ/9xJNCuKgeAHygqCKv CxN5roknDKNAENlsm43rBzv40iT/CsTGUUeWSmdfML+n6yNvXbiXW8Iyzrx+LQR86pF8 oXsKQAViQ7v5WYtuAHzpW9pBQrMQUE9T0frvwvlS5RIBv+11usg6JrgorbkEu4y/bs3G 9dug== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=G7fRU4wG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a05640203c200b004825e4a6946si2961235edw.371.2022.12.24.08.38.00; Sat, 24 Dec 2022 08:38:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=G7fRU4wG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231317AbiLXQeo (ORCPT + 66 others); Sat, 24 Dec 2022 11:34:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229688AbiLXQem (ORCPT ); Sat, 24 Dec 2022 11:34:42 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72BF6BC24; Sat, 24 Dec 2022 08:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1671899673; bh=JOlABxyXfYqHNmeXEA2u7PKdxsmIADwnMI+IIPAofYs=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:In-Reply-To; b=G7fRU4wGfAc6gzasYNgExIne6OeHxLd2yQwgYqH9UVM9hGaioJ7GT+snkxYaZHzmF T9rz25g8S5NVnzAC5x63nQIRo7d0WY5dNkAVSHrJJct00oswLDiQ/RkyEtlq3STeTa A/YzBd4wTuc4D//7kxpGMBaj/TN4pLeXbOQkf9ns= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via ip-206.mailobj.net [213.182.55.206] Sat, 24 Dec 2022 17:34:33 +0100 (CET) X-EA-Auth: u5gVJF6h2z6ranrprLxW6HFUwyiomyX6r//ovjc1j/VosSoEw1Ak2Lw/JbyumNnUO9AM56Ey8DrPTbNA0EQfj9lOo+WcqNpx Date: Sat, 24 Dec 2022 22:04:28 +0530 From: Deepak R Varma To: "Maciej W. Rozycki" , Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar , Deepak R Varma Subject: [PATCH 2/2] tty: serial: dz: convert atomic_* to refcount_* APIs for irq_guard Message-ID: <51ef854f77779c82010379420139993e12c38776.1671898144.git.drv@mailo.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The refcount_* APIs are designed to address known issues with the atomic_t APIs for reference counting. They provide following distinct advantages: - protect the reference counters from overflow/underflow - avoid use-after-free errors - provide improved memory ordering guarantee schemes - neater and safer. Hence, replace the atomic_* APIs by their equivalent refcount_t API functions. This patch proposal address the following warnings generated by the atomic_as_refcounter.cocci coccinelle script atomic_add_return(-1, ...) Signed-off-by: Deepak R Varma --- Please Note: 1. The patch is compile tested using dec_station.defconfig for MIPS architecture. 2. This patch should be applied after patch 1/2 of this series due to dependency. Changes in v3: 1. Include the individual patches in a series and highlight dependency. Feedback provided by gregkh@linuxfoundation.org Changes in v2: 1. Separate the combined change into one variable per patch as suggested by gregkh@linuxfoundation.org drivers/tty/serial/dz.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/tty/serial/dz.c b/drivers/tty/serial/dz.c index b70edc248f8b..0aa59a9beeb7 100644 --- a/drivers/tty/serial/dz.c +++ b/drivers/tty/serial/dz.c @@ -46,7 +46,6 @@ #include #include -#include #include #include #include @@ -77,7 +76,7 @@ struct dz_port { struct dz_mux { struct dz_port dport[DZ_NB_PORT]; refcount_t map_guard; - atomic_t irq_guard; + refcount_t irq_guard; int initialised; }; @@ -400,18 +399,16 @@ static int dz_startup(struct uart_port *uport) struct dz_port *dport = to_dport(uport); struct dz_mux *mux = dport->mux; unsigned long flags; - int irq_guard; int ret; u16 tmp; - irq_guard = atomic_add_return(1, &mux->irq_guard); - if (irq_guard != 1) + refcount_inc(&mux->irq_guard); + if (refcount_read(&mux->irq_guard) != 1) return 0; - ret = request_irq(dport->port.irq, dz_interrupt, - IRQF_SHARED, "dz", mux); + ret = request_irq(dport->port.irq, dz_interrupt, IRQF_SHARED, "dz", mux); if (ret) { - atomic_add(-1, &mux->irq_guard); + refcount_dec(&mux->irq_guard); printk(KERN_ERR "dz: Cannot get IRQ %d!\n", dport->port.irq); return ret; } @@ -441,15 +438,13 @@ static void dz_shutdown(struct uart_port *uport) struct dz_port *dport = to_dport(uport); struct dz_mux *mux = dport->mux; unsigned long flags; - int irq_guard; u16 tmp; spin_lock_irqsave(&dport->port.lock, flags); dz_stop_tx(&dport->port); spin_unlock_irqrestore(&dport->port.lock, flags); - irq_guard = atomic_add_return(-1, &mux->irq_guard); - if (!irq_guard) { + if (refcount_dec_and_test(&mux->irq_guard)) { /* Disable interrupts. */ tmp = dz_in(dport, DZ_CSR); tmp &= ~(DZ_RIE | DZ_TIE); -- 2.34.1