Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3709969ybv; Mon, 10 Feb 2020 05:07:18 -0800 (PST) X-Google-Smtp-Source: APXvYqzobi4SHO2pv2Muw8gd8jiFzqqJua8RaI+aDmEZZtAnAbTyNJu9DvhqFvZgvW3/bUIvNaVE X-Received: by 2002:a05:6830:4cd:: with SMTP id s13mr950798otd.181.1581340038193; Mon, 10 Feb 2020 05:07:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581340038; cv=none; d=google.com; s=arc-20160816; b=NdjVxwFdjtBATOF1S8ARWZNY1LTOoToWVrouqocc5jIb+2ZWXpCQOnVbcEM0hENrs6 czkZJ1nqStbDjjoIf7SMm5yq835YcOCNFGk+L7XV0euI0reqdXM+lT9Zi927lgLnbIJ6 5BhV9rGCsFQ6rYYMtsQ3REyK6iRiIZctoCYC0ozghpYJwt3ws4U+93efqgx9vC70HOkY 6xRF8Of3Y2NxW9KMzpRbeyVKqnt7JNA2Pty+XfFE1765kFwAomvdv9JJu8ESkonhsTmg BtvvWvSeyWjeS94NHOcTOdwEmbiRPeDChRc1hL0EIFFAFCm8HyUHO+3mLdSEGssfxbz8 o0jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DDJdTUhNRx+FSVrIt7fK8ntD5hYr5eIjJadlyuyjV/s=; b=bzjzmEEnidJwRP1sWbJkimvGnHKpVc5HeZlB0hwvBIiUI8ysPTFCwtVh9H3kJWmSKo jlKVNka/2brzVsonK8+0VK+nhvOoZ8MTIeq4jeDGYyaFHU6OEJ6l2O1qBvSr8LeBMdRM GrSp9eJtdDO/e9V43IEiA1Q9SPWrnYp76gXN4NVWMTf1IPHv5p5AoSWqfLlSOxK1N6hP q9V+AZJP5CdibchPBi1pXZBK+WxahFiLVeYgjNYnjtZHkPWrKhINGn4XBu4cgX6h61hl 0GidRiBK8OSOOxpde2qAubCQEvP1Ytl088bRQdrZ3fYv2h9NVD0BQiKhnI8FgFmnXA7l 2CmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="GLX/tMym"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j15si118244oii.163.2020.02.10.05.07.06; Mon, 10 Feb 2020 05:07:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="GLX/tMym"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730667AbgBJNFl (ORCPT + 99 others); Mon, 10 Feb 2020 08:05:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:39128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729597AbgBJMkB (ORCPT ); Mon, 10 Feb 2020 07:40:01 -0500 Received: from localhost (unknown [209.37.97.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6505E24650; Mon, 10 Feb 2020 12:40:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338401; bh=O6YsbmRPveSTEOfCkCjl0ByYf3LC/loyxyLTERL+99g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GLX/tMymmmznIiTRMZm5tZZsTUIDNf09f/dC8RMZSm3Vrw+/uM+E1gtBwwDTbg33l Mw1WFt3EQLtqTpBJTb1nKyVhkGskFhwKYYvIFd5n+tmdU+tM4YFwP4Tzp7oca9rNJQ JExjtoR8BZQ1XDu63PB9Zkza/GEXjhFvBmVnDLEQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephen Boyd , Thomas Gleixner , Douglas Anderson Subject: [PATCH 5.5 100/367] alarmtimer: Unregister wakeup source when module get fails Date: Mon, 10 Feb 2020 04:30:13 -0800 Message-Id: <20200210122433.597241894@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stephen Boyd commit 6b6d188aae79a630957aefd88ff5c42af6553ee3 upstream. The alarmtimer_rtc_add_device() function creates a wakeup source and then tries to grab a module reference. If that fails the function returns early with an error code, but fails to remove the wakeup source. Cleanup this exit path so there is no dangling wakeup source, which is named 'alarmtime' left allocated which will conflict with another RTC device that may be registered later. Fixes: 51218298a25e ("alarmtimer: Ensure RTC module is not unloaded") Signed-off-by: Stephen Boyd Signed-off-by: Thomas Gleixner Reviewed-by: Douglas Anderson Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20200109155910.907-2-swboyd@chromium.org Signed-off-by: Greg Kroah-Hartman --- kernel/time/alarmtimer.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -88,6 +88,7 @@ static int alarmtimer_rtc_add_device(str unsigned long flags; struct rtc_device *rtc = to_rtc_device(dev); struct wakeup_source *__ws; + int ret = 0; if (rtcdev) return -EBUSY; @@ -102,8 +103,8 @@ static int alarmtimer_rtc_add_device(str spin_lock_irqsave(&rtcdev_lock, flags); if (!rtcdev) { if (!try_module_get(rtc->owner)) { - spin_unlock_irqrestore(&rtcdev_lock, flags); - return -1; + ret = -1; + goto unlock; } rtcdev = rtc; @@ -112,11 +113,12 @@ static int alarmtimer_rtc_add_device(str ws = __ws; __ws = NULL; } +unlock: spin_unlock_irqrestore(&rtcdev_lock, flags); wakeup_source_unregister(__ws); - return 0; + return ret; } static inline void alarmtimer_rtc_timer_init(void)