Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2121924rwb; Thu, 19 Jan 2023 21:30:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXvvQiwL5XEoZg3Xs91AIbMzc/k+aXMt86Gd0nUN0VhhA9OqEX6dJoYEILmwloKI3nvf5IfT X-Received: by 2002:a17:906:40a:b0:86f:a21d:62b7 with SMTP id d10-20020a170906040a00b0086fa21d62b7mr13576276eja.9.1674192652808; Thu, 19 Jan 2023 21:30:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674192652; cv=none; d=google.com; s=arc-20160816; b=AQhWsBGdOpYhhmF75UzCINOeb+Qjlqi9NOlRXOCL/11lyr4lvlqvZC7LuNtxDq16Xs 8Yt47yB5kqC8UJKRHaemJpufk73uvnjWIr8nFxYeeZVN9eofDknNqKLqtHDc0RI/LFA9 KALiedGcqS57kUBZAzluSmShpr2O00m5VLy8MrwjQgKl6tz5mLaV/CbrmtoiMEW/j5YY VF3qZsakk3BdauokUDePPLaiio/Cg1Msc5uX5lMej5j9otcuU9Bb6SkdzGRdK2XUxXjB ZdUDnxvbvOKqcSY8vRLXeifL2fNIUqOM3p5ducvC78Iii0GiYEOKQDhijEindOh9LFl2 rOsw== 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=zDNCLSvsVcTEhMjRMVRQsj5eiPbMo8/M3VzQp6jzhaA=; b=pkIelFleSbrLqOKox7KaxZ7yr9VwcnOmuwDbu9COPsvnr/qv0niuQnEp8omT4RzDDb tot7KjniQ3KDbGCyrgZAwxY6+TrWAzLqRZKczbXjCu5RW7OG/KqGAFEhM5/E2CvcZwvy XgjZkyHewpvbKPlnhiIOqdaN71NLlOb3LsBJvXg6AL1D8u8O4pCzwbP30kig3gtLKa5p JG6T5R5+YGm89JfAGe5+Vb4PgaTZ+c1Ohb31db9Wjz8+vUrYgXAxdGFladR+fAAa0t8w Hj5x076/ceySvm7W/RF+IleJoItaU4/UrPntY5QelOj9iT5QvH+HOvSjfUDj7Q/Vzu1O KhLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L4nGtipd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp18-20020a1709073e1200b0087780ff7e31si3649733ejc.640.2023.01.19.21.30.40; Thu, 19 Jan 2023 21:30:52 -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=pass header.i=@linuxfoundation.org header.s=korg header.b=L4nGtipd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231210AbjATFT4 (ORCPT + 47 others); Fri, 20 Jan 2023 00:19:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbjATFTg (ORCPT ); Fri, 20 Jan 2023 00:19:36 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7AFA7DFAB; Thu, 19 Jan 2023 21:09:04 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B087BB823C8; Thu, 19 Jan 2023 13:52:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEC78C433D2; Thu, 19 Jan 2023 13:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1674136364; bh=o+MRE6eQh3jzlCO0huiyyivHqXsZNKLN474B0e3rGRE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=L4nGtipd7FU1P1/x5hzKoWzI5HH1TKPIRz3pHdvW05AXZVhuGmgxNnaiOq8bPgEGp tzd08EWg6bodxd/jMNDAtktV/Pc5rmfLKFrOe1yOltDXgrtze0tnReystUyT8H8u// JLkQv3BbqAC8KBXElvwjapOzMa5JvSdrGRsEnzlc= Date: Thu, 19 Jan 2023 14:52:36 +0100 From: Greg Kroah-Hartman To: Deepak R Varma Cc: "Maciej W. Rozycki" , Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Saurabh Singh Sengar , Praveen Kumar Subject: Re: [PATCH v2] tty: serial: zs: convert atomic_* to refcount_* APIs for irq_guard Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Sat, Dec 24, 2022 at 10:25:58PM +0530, Deepak R Varma wrote: > 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 > --- > > Changes in v2: > 1. Separate the combined change into one variable per patch as > suggested by gregkh@linuxfoundation.org > 2. There was additional feedback on validating the change as it appeared to > modify the existing logic. However, I found that the logic does not > change with the proposed refcount_* APIs used in this change. Hence that > feedback is not applied in this version. > > Please Note: > The patch is compile tested using dec_station.defconfig for MIPS architecture. > > drivers/tty/serial/zs.c | 14 +++++--------- > drivers/tty/serial/zs.h | 2 +- > 2 files changed, 6 insertions(+), 10 deletions(-) > > diff --git a/drivers/tty/serial/zs.c b/drivers/tty/serial/zs.c > index 730c648e32ff..6be9933eff5c 100644 > --- a/drivers/tty/serial/zs.c > +++ b/drivers/tty/serial/zs.c > @@ -753,17 +753,15 @@ static int zs_startup(struct uart_port *uport) > struct zs_port *zport = to_zport(uport); > struct zs_scc *scc = zport->scc; > unsigned long flags; > - int irq_guard; > int ret; > > - irq_guard = atomic_add_return(1, &scc->irq_guard); > - if (irq_guard == 1) { > + refcount_inc(&scc->irq_guard); > + if (refcount_read(&scc->irq_guard) == 1) { This conversion is wrong :(