Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp356146pxb; Tue, 12 Apr 2022 03:38:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyksj5JQVKWL50Y3VcSrhpl/pR2209J5hKDH0UaX5EIR/t8rRERmoUNcDIpvqOrJ6DLqk/m X-Received: by 2002:a17:907:2bf4:b0:6e8:93d4:46e9 with SMTP id gv52-20020a1709072bf400b006e893d446e9mr8356134ejc.69.1649759917809; Tue, 12 Apr 2022 03:38:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649759917; cv=none; d=google.com; s=arc-20160816; b=VX8X7Bf+itKaQC8MznyJY0j6kDhRAUcYYmYPs8CSfbKNCn6p1lLQxaFG9mz53EJ0K1 50E4ptieDSdXjqDA1/9glAB/OY6mNIjEAICMBzU1CD53WFyHcUxaTWAiPqhuisvVO2Ju nypC/aqaYfwlVCktuJl8ng+bsGKmv0ddCyhhSxLgHddU35pW7ZqAxVz+c5STEJ/txlEs Z9mh47RBjyhrF0kbsLQtdKRkOqxEgoxHhADuGWFj+N5pc59Qs9fRZaI+6NTwYuN1qEY7 l/e/7tx3bBvsj8Zc4/zmnP/oASZyKPrzlKwv+x6nR2gubdhqbxnBaohZpg2QqGrhIelR h5NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Jk6M0DbfHBN0zLnudjgrB69c9HcXkYUuA3+BM6Jtrw4=; b=kJ+GIj9z2cZJcVtbx0cmwIcsA+vXSGTa+MGHA7uD2JgiChEUU3uH5cKVqkPX2EApwT u4enDNm4V9Ur8GE4We4XoqP6zcXnZXwyBOk2fAcjanYlx1cd3xV65jZloe3T5sSjpY/u 4oCfLwde8j/24nbt5MMccjXQbQQE7uvOi8OCcx/KhFjTW5D7SieDQ8ide+RG044xSXdq HOzhNln75jOgEq9m1GeTP8R88iwISCFRj9cX4NgPlDqfqLktaGSVxVwqtHYe7809Q+FD hiZNQmoLEwdaeoRN9ybrSmxh7+Cwx8+YuwpieE9RudEzgUtRRoEhXTYsLzUZ4AYQtnuh JVIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=A9SlVEDp; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a056402190b00b0041d70a6c777si7249247edz.632.2022.04.12.03.38.09; Tue, 12 Apr 2022 03:38:37 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=A9SlVEDp; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347645AbiDKPMI (ORCPT + 99 others); Mon, 11 Apr 2022 11:12:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347598AbiDKPMG (ORCPT ); Mon, 11 Apr 2022 11:12:06 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB4342DD71; Mon, 11 Apr 2022 08:09:51 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id bh17so31513927ejb.8; Mon, 11 Apr 2022 08:09:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Jk6M0DbfHBN0zLnudjgrB69c9HcXkYUuA3+BM6Jtrw4=; b=A9SlVEDpcfZWlKCkgW4Ii0W+8+t2na/CW7KYHuT3p8rKlo8pXuQjWY1ZB4TlwTOttb YhfsZv0Rv9AKamOEw5VZi8vGk+K1V5OADFVzP8bm6N5PlC9ckXnUnq1ZstXu0KOYPujp iFl0c0DeLRHY+VHguqXnK9wwQbTtGTLbZVD2iHG/lH+yX1x/CxvBhe1F130seUI6TsRY MbslGLrWiyFZdx+VTcwsuixiWtu7+hQwV2XH0AsAVnMHCdprNIFRQN/+cMSx9OhcwHBy uf7QYc1oSUzePBewqV+lPl4wwSLqBjA0UYuYARHMwdHdXNGcbR7HTJItgEYYi798FGro ZlGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Jk6M0DbfHBN0zLnudjgrB69c9HcXkYUuA3+BM6Jtrw4=; b=DdG3ci9BD+bhHZMRMADM0YfT+1u919lQNHyZe0rGGT5DYM6MSsQricCiejCUpn7Jk/ n8sbVyJ5cypBgKIBZ+9a9I71+0MWqRWc5QrZY4QSC4FnoztP0m9El78XbsSMRg6CFj1u JIXe34jpgKRcNEfIue03ojjOZvdV3qqKHSIDvX1MV+voOeDN5uezSVR8WXMPrmDCAzLS nFHYgZDDIx2zDP3YZsY+Ah8q8xwAYQSf3z0xIBoZYCz5FsQsgQhfPBgCnQY7/h8wBSrp 7Ms4vQg07kiahzMfehM9pRupiD5PyH4l+xyNBS1ytaQ8+MgKKaSNU6PMBQe8GGiBh/h5 PEAQ== X-Gm-Message-State: AOAM530KtLIaXr3wQS3OJqF6n9lyxbaDfJviA+gh9Vfnr8nnMLM2QvKu 5ZlXp2c+6cAidXS0Ee4V5YF0zpSTzOpqmqWrFzf15RLLiD3z9A== X-Received: by 2002:a17:907:968e:b0:6db:aed5:43c8 with SMTP id hd14-20020a170907968e00b006dbaed543c8mr30659865ejc.636.1649689790278; Mon, 11 Apr 2022 08:09:50 -0700 (PDT) MIME-Version: 1.0 References: <1836398.tdWV9SEqCh@kreacher> In-Reply-To: <1836398.tdWV9SEqCh@kreacher> From: Andy Shevchenko Date: Mon, 11 Apr 2022 18:05:37 +0300 Message-ID: Subject: Re: [PATCH v1] PM: runtime: Avoid device usage count underflows To: "Rafael J. Wysocki" Cc: Linux PM , LKML , Ulf Hansson , Alan Stern Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Wed, Apr 6, 2022 at 11:49 PM Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > A PM-runtime device usage count underflow is potentially critical, > because it may cause a device to be suspended when it is expected to > be operational. > > For this reason, (1) make rpm_check_suspend_allowed() return an error > when the device usage count is negative to prevent devices from being > suspended in that case, (2) introduce rpm_drop_usage_count() that will > detect device usage count underflows, warn about them and fix them up, > and (3) use it to drop the usage count in a few places instead of > atomic_dec_and_test(). ... > + retval = rpm_drop_usage_count(dev); > + if (retval > 0) { > trace_rpm_usage_rcuidle(dev, rpmflags); > return 0; > + } else if (retval < 0) { > + return retval; > } Can be written in a form if (retval < 0) return retval; if (retval > 0) { trace_rpm_usage_rcuidle(dev, rpmflags); return 0; } ... > + if (retval > 0) { > trace_rpm_usage_rcuidle(dev, rpmflags); > return 0; > + } else if (retval < 0) { > + return retval; > } Ditto. -- With Best Regards, Andy Shevchenko