From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Rafael J. Wysocki" Subject: Re: [PATCHv4 04/11] PM: Use *_dec_not_zero instead of *_add_unless Date: Thu, 28 Jul 2011 23:43:54 +0200 Message-ID: <201107282343.54519.rjw@sisk.pl> References: <1311760070-21532-1-git-send-email-sven@narfation.org> <201107272150.37962.rjw@sisk.pl> <20110727203604.GA8468@elf.ucw.cz> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20110727203604.GA8468@elf.ucw.cz> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-pm-bounces@lists.linux-foundation.org Errors-To: linux-pm-bounces@lists.linux-foundation.org To: Pavel Machek Cc: linux-arch@vger.kernel.org, Len Brown , linux-pm@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Sven Eckelmann List-Id: linux-arch.vger.kernel.org On Wednesday, July 27, 2011, Pavel Machek wrote: > Hi! > > > > atomic_dec_not_zero is defined for each architecture through > > > to provide the functionality of > > > atomic_add_unless(x, -1, 0). > > > > > > Signed-off-by: Sven Eckelmann > > > Cc: Len Brown > > > Cc: Pavel Machek > > > Cc: Rafael J. Wysocki > > > Cc: linux-pm@lists.linux-foundation.org > > > > Acked-by: Rafael J. Wysocki > > > > > --- > > > drivers/base/power/runtime.c | 4 ++-- > > > include/linux/pm_runtime.h | 2 +- > > > kernel/power/hibernate.c | 4 ++-- > > > kernel/power/user.c | 2 +- > > > 4 files changed, 6 insertions(+), 6 deletions(-) > > > > > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c > > > index 8dc247c..bda10d9 100644 > > > --- a/drivers/base/power/runtime.c > > > +++ b/drivers/base/power/runtime.c > > > @@ -401,7 +401,7 @@ static int rpm_suspend(struct device *dev, int rpmflags) > > > > > > if (dev->parent) { > > > parent = dev->parent; > > > - atomic_add_unless(&parent->power.child_count, -1, 0); > > > + atomic_dec_not_zero(&parent->power.child_count); > > I'd like to understand... Why not atomic_dec in the first place? Count > should be exact, anyway, or we run into problems, right? Well, we'll also run into trouble if the count becomes negative. We might throw a WARN_ON() there if the old value weren't as expected, but that would be a separate patch. Thanks, Rafael From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ogre.sisk.pl ([217.79.144.158]:60338 "EHLO ogre.sisk.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753836Ab1G1WDL (ORCPT ); Thu, 28 Jul 2011 18:03:11 -0400 From: "Rafael J. Wysocki" Subject: Re: [PATCHv4 04/11] PM: Use *_dec_not_zero instead of *_add_unless Date: Thu, 28 Jul 2011 23:43:54 +0200 References: <1311760070-21532-1-git-send-email-sven@narfation.org> <201107272150.37962.rjw@sisk.pl> <20110727203604.GA8468@elf.ucw.cz> In-Reply-To: <20110727203604.GA8468@elf.ucw.cz> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-ID: <201107282343.54519.rjw@sisk.pl> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Pavel Machek Cc: Sven Eckelmann , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Len Brown , linux-pm@lists.linux-foundation.org Message-ID: <20110728214354.y6NNUjPQBRzCrKLPWHvkwoxSYiT94SV_PAimfHLsh30@z> On Wednesday, July 27, 2011, Pavel Machek wrote: > Hi! > > > > atomic_dec_not_zero is defined for each architecture through > > > to provide the functionality of > > > atomic_add_unless(x, -1, 0). > > > > > > Signed-off-by: Sven Eckelmann > > > Cc: Len Brown > > > Cc: Pavel Machek > > > Cc: Rafael J. Wysocki > > > Cc: linux-pm@lists.linux-foundation.org > > > > Acked-by: Rafael J. Wysocki > > > > > --- > > > drivers/base/power/runtime.c | 4 ++-- > > > include/linux/pm_runtime.h | 2 +- > > > kernel/power/hibernate.c | 4 ++-- > > > kernel/power/user.c | 2 +- > > > 4 files changed, 6 insertions(+), 6 deletions(-) > > > > > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c > > > index 8dc247c..bda10d9 100644 > > > --- a/drivers/base/power/runtime.c > > > +++ b/drivers/base/power/runtime.c > > > @@ -401,7 +401,7 @@ static int rpm_suspend(struct device *dev, int rpmflags) > > > > > > if (dev->parent) { > > > parent = dev->parent; > > > - atomic_add_unless(&parent->power.child_count, -1, 0); > > > + atomic_dec_not_zero(&parent->power.child_count); > > I'd like to understand... Why not atomic_dec in the first place? Count > should be exact, anyway, or we run into problems, right? Well, we'll also run into trouble if the count becomes negative. We might throw a WARN_ON() there if the old value weren't as expected, but that would be a separate patch. Thanks, Rafael