Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp511939yba; Mon, 1 Apr 2019 10:46:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9GrMDsALkjGpJI1ukQwX3NCFVZ9UBrMpsuKZzxYB86t00OvUQaehFsb5YQ9caxqMzJK4m X-Received: by 2002:a17:902:2a89:: with SMTP id j9mr63700757plb.272.1554140803748; Mon, 01 Apr 2019 10:46:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554140803; cv=none; d=google.com; s=arc-20160816; b=gOShIo+ikz+7S6JFg9EPtOtLcYNrz4qxx2a2Ctc7DT3Fb46eppFyAb3/8JjMddwMXh 9dM5uC/RcWC+PotimT0bR2/epwNq6YX6O+DOIUxoR3x6DSTOKL030ElTFeZjJROxsRIl my0VLOH/TwK6Sj9p1t0UPeli05+KmAZ6Sd3wYFza54TVlp4ixEmuQop5In7Zc0jwvmoD AiwmXDyJHKzcLZ1eoR2ogWOPdhdzGLI3UJ+Hs/v5Vger4E2pbkyDBEXsjOfpKqt9tMj4 GjAnFfXMJXOc7b4zWcNIcWOJvbYm8PVQZBdsoalZOkxcHiaSKhJkcjv/6VJD8RLkVo1l Y9lw== 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=/qWa5mTm7sR8RvHcV+jFd11oFy9/UBul7qRN3bJXKH0=; b=wfApmt+ltTFvtuuhCBXV/icErdFLmvK3JS98eNyyORZX4rlwfORgi73dARZcAI5ijh Bp6f1+yyIlpHwAyVmouJzqZnPeM5C04xUnPxAJNaO8RxW9/p/koe/Uz6FAjxXbUNnYpt g3gMskFLxdfF0B7HLrqQmehseq1bvOV7PymQq5IbfLAR0KgLwm3HxvTU88MVW/qiuvS8 iFNUYvI0nOez4JZA1jc0hjcOdcNlqf3ky5xqOWsVkQZqDxz0+/xIJz0CmaxFxYCQxfM+ TlJBFWc7dwq8ScXjYn4cARo42Bjx9rPOM9p6LGfLl7bKDRKcgRg9GS98pHhTEC5OLOzp QiMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=G4f1BY0D; 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 m3si8945894pgp.263.2019.04.01.10.46.28; Mon, 01 Apr 2019 10:46:43 -0700 (PDT) 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=G4f1BY0D; 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 S1733261AbfDAReB (ORCPT + 99 others); Mon, 1 Apr 2019 13:34:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:43348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732498AbfDARd4 (ORCPT ); Mon, 1 Apr 2019 13:33:56 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 BD57720880; Mon, 1 Apr 2019 17:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554140036; bh=zZPhG5F5/OrS61Q+SRZCGay6spaiqmgMoLP8G0Ft98g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G4f1BY0Dy++my/NiaS7RafSYuSCrjoRnd6JaQMgtQFbmM9jzaPLI72fxXCmPoHPpo ciTn/Bph9UWdXiuxMQb4VnE+Mkzcou6Za+dpaO+kYpBrD6vsXZteIdvA0JIfWwco/r nLE8pJztR1lVu1gyS9RCzpxjYgKb2JfVVW+qaxDY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Cox , Alexander Shishkin , Laurent Fert , Sasha Levin Subject: [PATCH 4.4 080/131] stm class: Fix stm device initialization order Date: Mon, 1 Apr 2019 19:02:30 +0200 Message-Id: <20190401170058.821301370@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170051.645954551@linuxfoundation.org> References: <20190401170051.645954551@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 389b6699a2aa0b457aa69986e9ddf39f3b4030fd ] Currently, stm_register_device() makes the device visible and then proceeds to initializing spinlocks and other properties, which leaves a window when the device can already be opened but is not yet fully operational. Fix this by reversing the initialization order. Reported-by: Alan Cox Signed-off-by: Alexander Shishkin Reviewed-by: Laurent Fert Signed-off-by: Sasha Levin --- drivers/hwtracing/stm/core.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index 0c7f0bae001a..b6cc841de79d 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -664,18 +664,11 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data, stm->dev.parent = parent; stm->dev.release = stm_device_release; - err = kobject_set_name(&stm->dev.kobj, "%s", stm_data->name); - if (err) - goto err_device; - - err = device_add(&stm->dev); - if (err) - goto err_device; - mutex_init(&stm->link_mutex); spin_lock_init(&stm->link_lock); INIT_LIST_HEAD(&stm->link_list); + /* initialize the object before it is accessible via sysfs */ spin_lock_init(&stm->mc_lock); mutex_init(&stm->policy_mutex); stm->sw_nmasters = nmasters; @@ -683,6 +676,14 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data, stm->data = stm_data; stm_data->stm = stm; + err = kobject_set_name(&stm->dev.kobj, "%s", stm_data->name); + if (err) + goto err_device; + + err = device_add(&stm->dev); + if (err) + goto err_device; + return 0; err_device: -- 2.19.1