From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6904EC678D6 for ; Fri, 20 Jan 2023 05:19:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbjATFTz (ORCPT ); Fri, 20 Jan 2023 00:19:55 -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: Precedence: bulk List-ID: X-Mailing-List: linux-serial@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 :(