From patchwork Thu Sep 8 02:07:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 9320285 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 19996607D3 for ; Thu, 8 Sep 2016 02:08:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02C04294DE for ; Thu, 8 Sep 2016 02:08:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9DFE294E0; Thu, 8 Sep 2016 02:08:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 16A0F294DE for ; Thu, 8 Sep 2016 02:08:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DB1046ECA8; Thu, 8 Sep 2016 02:08:32 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0088.outbound.protection.outlook.com [104.47.34.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id BD6F96ECA8; Thu, 8 Sep 2016 02:08:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=7FGzN0W3t0N0+pb67uqHzFTXvZu/M4Ee6M1rWuo9n5I=; b=lYNoqYjie820dzj5tjGqFTT/Xt9OTHbrS+X8OTVXfJH9N5DpnWnKDTtP6OlsPqvYBNJPf6Sg4UVW5PzxzwJwgh5633mYtb0qOiGfFitRefk91p7dHhpklFKfD1YmvZIrWpUzf5f2Nu716nCXaoLR/w1GovcXGBlLv6ia2YudrcA= Received: from BN6PR12CA0004.namprd12.prod.outlook.com (10.168.222.14) by BY2PR12MB0370.namprd12.prod.outlook.com (10.162.84.21) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.549.15; Thu, 8 Sep 2016 02:08:28 +0000 Received: from BY2NAM03FT038.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e4a::204) by BN6PR12CA0004.outlook.office365.com (2603:10b6:404:12::14) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.609.9 via Frontend Transport; Thu, 8 Sep 2016 02:08:27 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.22) smtp.mailfrom=amd.com; chromium.org; dkim=none (message not signed) header.d=none; chromium.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.22) by BY2NAM03FT038.mail.protection.outlook.com (10.152.84.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.587.6 via Frontend Transport; Thu, 8 Sep 2016 02:08:27 +0000 X-IncomingTopHeaderMarker: TopHeader Received: from SATLEXDAG01.amd.com (10.181.40.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server (TLS) id 14.3.266.1; Wed, 7 Sep 2016 21:08:19 -0500 Received: from SCYBEXDAG04.amd.com (10.34.11.14) by SATLEXDAG01.amd.com (10.181.40.3) with Microsoft SMTP Server (TLS) id 14.3.266.1; Wed, 7 Sep 2016 22:08:18 -0400 Received: from viwan-emmc.amd.com (10.237.75.121) by SCYBEXDAG04.amd.com (10.34.11.14) with Microsoft SMTP Server id 14.3.266.1; Thu, 8 Sep 2016 10:08:00 +0800 From: Huang Rui To: , Alex Deucher , Dave Airlie , =?UTF-8?q?Christian=20K=C3=B6nig?= , Daniel Vetter , Sean Paul Subject: [PATCH v3] drm: modify drm_global_item_ref to avoid two times of writing ref->object Date: Wed, 7 Sep 2016 22:07:57 -0400 Message-ID: <1473300477-2864-1-git-send-email-ray.huang@amd.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-IncomingHeaderCount: 13 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.22; IPV:CAL; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(428002)(199003)(189002)(48376002)(106466001)(105586002)(8676002)(626004)(4326007)(19580405001)(5660300001)(586003)(87936001)(19580395003)(8936002)(50226002)(33646002)(229853001)(53416004)(77096005)(2906002)(189998001)(92566002)(47776003)(7696003)(246002)(101416001)(356003)(7846002)(86362001)(305945005)(11100500001)(5003940100001)(36756003)(50986999)(26826002)(5001770100001)(50466002)(5001870100001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0370; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:hybridsmtp.amd.com,hybridsmtp02.amd.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2NAM03FT038; 1:XrXGb0b6vulO3U+VDnmh7P7pTB+nwXgA74xzSUm47uYT6bVFQH801MYVQGTCp3Gtwbw4Jyzj5tgyz72yIubQcDl2D5YexEv3/L+sucTDBtQP6k/rmZihYCYW323r6IvK9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lsvQ3WAPvp1E6hU1fah6udg/DtKDbDI5KUXbdKFnh9SPLMJY/HZmQfjQ6zTfTOzALfsRmkYZWQaEzfXvuEybwHkBMWBW7cLGO2oDyFiqXveDW0Op30FvMHO X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13013025)(5005006)(8121501046)(13023025)(13021025)(3002001)(10201501046)(6055026); SRVR:BY2PR12MB0370; BCL:0; PCL:0; RULEID:; SRVR:BY2PR12MB0370; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0370; 4:tEQVOYHRORhYAUulUzYUoozx+VRGPSU6tIB9rrzCtSb5/1IIU2Tr9CjAP2bboy9NP13Mx1jOkzP4e1NJ4clYSp2arw1MNfY5h68k1bm2uWTfjmzWVqAfmO12ujDL13Ep7HS3LWQWvZ+w8JJhfyhBJkcGPdfwrOdnFTgT/LlsPmFwZX8gQTPy8r9/db3uPF3Xn57kX4vmF2VBmpeARdidFLb4v9mr+Sta01OkQvhtK7HIOTxQ6KV1gNgoLcRPD91YRJJ8oGKbRZpGGD5P1vE2KN4ZO4gobyi1obCWg9T4LC8zHBXis57RPh1GyHZxeKTMpS9wphWK+33B7S5Eg9XSSnGqPdjPSZKbxDa/ZGI9CUAU+LYsynCxBQ+wTWSya8+gYDpgRJIat1epGq0aFGgSSkdaCD7AnJDVZOEJ7Afp+QKgfNkBcu3Qgj1XbT0s2cqOqDmla/GZ91MEVZFqUHJsvkPPXcz1B+kiEKdsxkfr+LSz59s33ax0bRwFuT7zTgpW X-Forefront-PRVS: 00594E8DBA X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR12MB0370; 23:Sc2z2Z9x9lj9tBhW2gc7AFzjDsni8aYkteh7ALfVK?= =?us-ascii?Q?qM6S7FC+/vgk1cbmyPFTc+QZi8Qi7i7AeUa9Yv/6eSP0MxcnHyW5H50ntnrY?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nosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0370; 20:M/ZHR8ge8eI17bQK4Y1X50V2EHhHlAVz764HsmZsXjuWO+U6Fl0BYaPc12kXlxjHwyfBo/QTJRzc2S7rbxl/cc8mGNIL/BSOG0cqAEaRu0Ty6WMG53WJ+MtkqMOGJjrxDAg5Zw9E1vO8CrPVuQemUosdLUc7tCqYq+0u6g1UKwFeVNiqOpP3CAfdW3k8By4iuErMU5VcnAsEXtd/S2GB5L1AWGxI7CxOvg2G4LC0OtdFHufKrLrQkvNhcZakAW// X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Sep 2016 02:08:27.1998 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.22]; Helo=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0370 Cc: Ken Wang , Huang Rui , amd-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP In previous drm_global_item_ref, there are two times of writing ref->object if item->refcount is 0. So this patch does a minor update to put alloc and init ref firstly, and then to modify the item of glob array. Use "else" to avoid two times of writing ref->object. It can make the code logic more clearly. Signed-off-by: Huang Rui Reviewed-by: Christian König . --- Changes from V2 -> V3: - Use duplicate mutex release to avoid "goto" in non-error patch. - Rename error label --- drivers/gpu/drm/drm_global.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c index 3d2e91c..b404287 100644 --- a/drivers/gpu/drm/drm_global.c +++ b/drivers/gpu/drm/drm_global.c @@ -65,30 +65,34 @@ void drm_global_release(void) int drm_global_item_ref(struct drm_global_reference *ref) { - int ret; + int ret = 0; struct drm_global_item *item = &glob[ref->global_type]; mutex_lock(&item->mutex); if (item->refcount == 0) { - item->object = kzalloc(ref->size, GFP_KERNEL); - if (unlikely(item->object == NULL)) { + ref->object = kzalloc(ref->size, GFP_KERNEL); + if (unlikely(ref->object == NULL)) { ret = -ENOMEM; - goto out_err; + goto error_unlock; } - - ref->object = item->object; ret = ref->init(ref); if (unlikely(ret != 0)) - goto out_err; + goto error_free; + item->object = ref->object; + } else { + ref->object = item->object; } + ++item->refcount; - ref->object = item->object; mutex_unlock(&item->mutex); return 0; -out_err: + +error_free: + kfree(ref->object); + ref->object = NULL; +error_unlock: mutex_unlock(&item->mutex); - item->object = NULL; return ret; } EXPORT_SYMBOL(drm_global_item_ref);