From patchwork Wed Sep 7 05:24:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 9318189 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 A4E5E6077F for ; Wed, 7 Sep 2016 05:24:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 823B629004 for ; Wed, 7 Sep 2016 05:24:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 610F029018; Wed, 7 Sep 2016 05:24:47 +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 6487A29004 for ; Wed, 7 Sep 2016 05:24:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5D6216E894; Wed, 7 Sep 2016 05:24:44 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0081.outbound.protection.outlook.com [104.47.42.81]) by gabe.freedesktop.org (Postfix) with ESMTPS id D48906E893; Wed, 7 Sep 2016 05:24:42 +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=brr7q/Hcl9QfNnmXqLiYnq2nQo+UX/kJd3TvHcnKSw8=; b=WidbrZYiy46Z1id8HKXBCkAfn1sM69vqeUhDbLo3U482U8JyEddCztwS9Xf/Mjw3vAHIqkJYKqoHaO75L+a84c1wgofPZL/5fuYc9dDQbZ1vCWS5V9jizcueFJEL9f8X42wocsY7pdjjX63l26kqisstvl2VMiWVDm/VOZ+MLzc= Received: from BY2PR12CA0011.namprd12.prod.outlook.com (10.160.121.21) by BN6PR12MB1153.namprd12.prod.outlook.com (10.168.226.143) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.599.9; Wed, 7 Sep 2016 05:24:40 +0000 Received: from CO1NAM03FT028.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by BY2PR12CA0011.outlook.office365.com (2a01:111:e400:2c84::21) 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; Wed, 7 Sep 2016 05:24:39 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.22) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.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 CO1NAM03FT028.mail.protection.outlook.com (10.152.80.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.609.6 via Frontend Transport; Wed, 7 Sep 2016 05:24:39 +0000 X-IncomingTopHeaderMarker: TopHeader Received: from SCYBEXDAG03.amd.com (10.34.11.13) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server (TLS) id 14.3.266.1; Wed, 7 Sep 2016 00:24:38 -0500 Received: from viwan-emmc.amd.com (10.237.75.121) by SCYBEXDAG03.amd.com (10.34.11.13) with Microsoft SMTP Server id 14.3.266.1; Wed, 7 Sep 2016 13:24:34 +0800 From: Huang Rui To: , Alex Deucher , Dave Airlie , =?UTF-8?q?Christian=20K=C3=B6nig?= , Daniel Vetter , Sean Paul Subject: [Updated PATCH v2] drm: modify drm_global_item_ref to avoid two times of writing ref->object Date: Wed, 7 Sep 2016 01:24:31 -0400 Message-ID: <1473225871-2847-1-git-send-email-ray.huang@amd.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-IncomingHeaderCount: 12 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)(979002)(6009001)(7916002)(2980300002)(428002)(199003)(189002)(50986999)(8676002)(626004)(8936002)(586003)(86362001)(5660300001)(15650500001)(53416004)(87936001)(19580395003)(105586002)(19580405001)(16796002)(106466001)(33646002)(229853001)(189998001)(4326007)(5003940100001)(47776003)(36756003)(48376002)(5001770100001)(11100500001)(101416001)(2906002)(7846002)(92566002)(356003)(246002)(26826002)(50226002)(7696003)(77096005)(50466002)(305945005)(5001870100001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1153; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:hybridsmtp02.amd.com,hybridsmtp.amd.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CO1NAM03FT028; 1:V6JDTkn6gKkPWeXIRclQjFd1Ov4BFizii25NPOoNexEPvt4x80kqnzCAPb+IRNCw5kcHcC8S8izLgEu2mmTbGMYbu5bfxCIuaT4XPrs+tGHrxdic28v4YIbHEW9wnb2TPIckiDWrejvVuvGlSjPaCEz3++fOV/f5K/E/tsaKSA0MECkg9NRfLyIeAvKXFm7m5wPbfJ2hzGehqALmrvmicA+WBQRd4uUMNBNLSZV5HVvtdwNgYL8A3pMACAk6Nq8OSknFHPIITnnXVmqk6An9qrypZNh9hd+zQbusfgbLUcDV+JyUHNM9+VsAyOneUd2mGH69aeerxYa/FgL/MepmpwgqnCv6Dw7Pl350JM3ijDU6upbfZD5KLA00526nqAF+wshEPUk3jFHNYovO8/1bO0vYAX0r79L0P6Fdm9cNTZhEI9pnrphO0D9mV3ezSeKUNOZRxIlQ/ynONEo7KhNOGIxjNPnzHUwRD+SxSa0fT3KUvop3/AGdgZ7IRDdaJe8CoOXIK0InHumIyJQO1xz+Mg== X-MS-Office365-Filtering-Correlation-Id: 1373bcbb-9c58-46e9-49a0-08d3d6df43e5 X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1153; 2:MkQz1GvrLRnhnKJhraXmQkE2kzMlVnRccikrCHaoi8wjDSo3tKkU/CQcQrINmKYo24F+9maLe6bYRV11wEffyrNMXoDM759G5r2uvY1OJBeG2fQIGNOaIVzxnCitxszsOTT1mGMjfq9HJeLqJ3Ez5bZH1S0Yr9UfDRIm9vUZh3us2X6IYzKUJfk51H1jYUuT; 3:sShu1IrJfsYH9MGzOcGJukd2LxmLuRIZkdq5juCE6UNgaRRGBZHCKy7mIh0ZEZRgPnlH3yphl6uH41ugQ84rYCJj3iUiN1KVpSc+FIuYTfW2tcbOSuKIlbPzVTkUUVUT+mMlQjRa3FmHSazPaJOCeZSk4vAdY0ByWVYEKodzRgUCzW56HNimcozf+IEu7TICJgbDwvH8TgoCkhRQMfC31Gq96ggO6H0w4zKkJhhq/z8= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN6PR12MB1153; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1153; 25:ZRmMuO3acjq5mEr4ncWxJAYGz/AhY2bJy6IfSRixjNWTHxqIZEInacbEnUnLbMRIzbIZ0tPgSED7Zsdq9uiX8vUkMwhA5SBXBhkIRQur0fRoh2oIcgL/64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pGCBSqdA5jJ8pB+QqwWGCXU4H9UHMR1x/AwQV9U0ETmOD5s7dvpKu4XfVajdwDIiFn1wDUsY9GeSBxSu3BJG6LlJK1NrApXZwB3YWcUNTMTLdlNqSK5TSDgPFloOKxipp7eCZe3EgEqmtGEOPJmIjk09FNA4pGAiJJvR2cUghBO1jyDMP/R7uSLWo4W+ZJnFN4yaqj96BMfhdlu0wHW8onyGXRxOcLeKpw56nLs3h0okYZoR4QYoHiUqYH8VLJnMFEqxcAw3h79ccttczbX93Pp3y9+KubSV5p8G1AnF9wUZs0wZ9+CEhG1LFrYoYvU4/x0IGoLorGlWcJ78rDOZG9Zm 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)(13023025)(13021025)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:BN6PR12MB1153; BCL:0; PCL:0; RULEID:; SRVR:BN6PR12MB1153; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1153; 4:BojubwfRIfmekaCBrGP+DeBurlO9CNlJJby8zSPIVJodJ6smTIP87UaRGwr8rF+jXH173XvmIFj8vT+3nR6yr4QWhY776qmhRhTElNMj4TLaFSVWbPOz5N0ggtrX026EoCdcQmkZil6yGdpOL/2/3jfgNGhUW3SJ5VsLvKC3yqxwaPXiKFt4mwx7jjfk8kKDXddVqy69Moe7ZwJ+l4xGk9iq0RitgOQN0aP+HvmRT7ckEjQGcUt8MlhSpi9Ji8wp/2UTmjslSWr1fD5ud1pNepNXiBvsxThS1HDTkOUbmvp0QJqcPeqGo7SZnj5CVv/zGGR4q4ydbtS9ugpiuRGWVDIfqQ64dU4CQv6is11NHEYNEJLL5KCY+yhUcx53RppAlYSWYT47orjNcOByccq6nG0whPfOSKeMIGMfdTaO2Mg05QC0kooGgvPRIlLertZlL8dUNoROTTjkmYsk3YAfBeqL8oI4nDJmkZ3lXMAKMxBGbFPcX3gtZok4suadvvlR X-Forefront-PRVS: 0058ABBBC7 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR12MB1153; 23:YZFdRb+R2YiTeBADkZQWd3VN61ESPlRaL/iqs4h0M?= =?us-ascii?Q?qMp2B/p9jgbSYoGBLNhHCk4q7WDOwPJEqBlQxbcnpVDgbabgo0sbQVRidVvm?= =?us-ascii?Q?r+3XS33vxOzv9J8oCCYJZgtXaAyCjPaD8KufUBdjM1gDknL1eOYjpdGnwFfR?= =?us-ascii?Q?9NOryYXjdKA6FH6qUle48pTJmmR7ifwJbxuEoA/RBkmUhX11XMyS8y7agfF0?= =?us-ascii?Q?LowtHV/6AdHjs88ylqp6y3XwZ1c6nd9OGelOObpc1UEttJkyZGemvoicH8TL?= =?us-ascii?Q?yEYH2w6645Ax2myoLCAHnlMRgpvufhn3+3eJ3x+J9ROC9jZQhoPrzpRhiPIj?= =?us-ascii?Q?7Np0YCoe+jjJ7tOkZqjlur44UkFaDiIZ93o6QCNx+14bqLq4SgaNbX56wSg8?= =?us-ascii?Q?6VMWJ/inNAtWT6J/rIh4foPDH9czHCnv7uZ259NT60GFOKVffoeAlEmO39Wc?= =?us-ascii?Q?9iIZb4PnbEM0otFyvC1phEdXDPtNzfmvJ3CZy+rT78OWrScTGyv7fCxRLIDv?= =?us-ascii?Q?zf1a0rybSfMeIgDzKdhi4s3HgRy8myUpUIXmK9PL6VoFxsd4u3MWvlvx7P+7?= =?us-ascii?Q?mUX2N6Um3sQsUWoqJcr00ZbfZ7ZvRgH1FLexy9tEuaC0LzZMqJlqsINQx01R?= =?us-ascii?Q?szxSZDxgRoPODEQQl/DvuDccf1LmaNQpwzlJvTd2r8paAdIBYWc199KOAB/w?= =?us-ascii?Q?RwOVKsessv6Kiaxufmy3Dbrro1an/za4ZM+wMtpu8VbtTYaOov+2sfImITW6?= =?us-ascii?Q?2TF7mj8tz918XAjRBVKWovT4oRqz6Z3VQtHDEAA/zsPtao1WeT1Fz6C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S6h+8QhWYkmlELo2/BjdOOyf7z7K/nEarHKoe9nyLhMeZSZEw143xKYWEgsliDBEjNcSQSgv88ppnjSX76uFrvPH+NGJe6B1YgkifiPASyE=; 7:gMnA4KwpEc/Qi4go5zpaZHLyopL8+pLtCt6rbvprVEm92UF146SsM7KgbH/K5S56oFcgjkYUuEKLy6gmJqCpNXpXA/aCgUmUfBJLEn2oIXXysg54AQ5giK/92qOP1SMJ3cUv2py3N7WS8p347z0HjqjjOaDIk8lmjGIcMamXi93sTsqmthdUR+qbPnAON326f+35LPlwssSlDDXPV+cGcjLgaVqc2cPLRqFfeok99x03U3e32yEwp1WuXuF5DRdA SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1153; 20:uZnVx2ZsoJ3Q/Pm1E/TxTYmLBsVU0WWnZVF3HvrRS044QnRnVHz+xSAOLmh9I5cAn+/VACY9QzvBVBKw74EXoa8/OnwqmKaLeQ+LdQgycg6P/4S3/pGkZaWpu2CSPbXC42XW+k2qJwB7kEOQebCkxSbWXLlF+32wK7SrHkzNdBDL7grdv7E17j+hGbHtsTp7021jHVm5IlaZRbTL/GBE8OKjquybda6OuCWh0HEW/MAX4/0u0LStGtAfCo/p2gMH X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2016 05:24:39.0929 (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: BN6PR12MB1153 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 --- Changes from V1 -> V2: - Add kfree exceptional handle to avoid memory leak. - Improve code style. --- drivers/gpu/drm/drm_global.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c index 3d2e91c..b181e81 100644 --- a/drivers/gpu/drm/drm_global.c +++ b/drivers/gpu/drm/drm_global.c @@ -65,30 +65,33 @@ 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 out; } - - ref->object = item->object; ret = ref->init(ref); if (unlikely(ret != 0)) goto out_err; + item->object = ref->object; + } else { + ref->object = item->object; } + ++item->refcount; - ref->object = item->object; - mutex_unlock(&item->mutex); - return 0; + goto out; + out_err: + kfree(ref->object); + ref->object = NULL; +out: mutex_unlock(&item->mutex); - item->object = NULL; return ret; } EXPORT_SYMBOL(drm_global_item_ref);