From patchwork Mon Sep 5 07:00:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 9313947 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 A04FB607D3 for ; Mon, 5 Sep 2016 13:32:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91A6628AAC for ; Mon, 5 Sep 2016 13:32:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8680C28AB0; Mon, 5 Sep 2016 13:32:43 +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 7B61328AAC for ; Mon, 5 Sep 2016 13:32:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A5F116E3F3; Mon, 5 Sep 2016 13:32:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 21494 seconds by postgrey-1.35 at gabe; Mon, 05 Sep 2016 13:32:38 UTC Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0060.outbound.protection.outlook.com [104.47.33.60]) by gabe.freedesktop.org (Postfix) with ESMTPS id E0A876E3F3 for ; Mon, 5 Sep 2016 13:32:38 +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=1bIqFaaoh7KaRuocXjqZEN8sder6c1ZrgXZKny03zkI=; b=IGV+jhO1H+dekiiinpd8sRHT/NCGFygRDwFanqdA34UN87wT4PQ9sfDHnNoR6a0jEYCN4keTBBmd01VCCFUKWSKhSl4h3j7qWn6VuXFfHe7C4UdFQu6yXUOAdMejqY8KGVKc3/g5TISf3VjB6MLXxS7UOryvo0H20pw100bzPIY= Received: from SN1PR12CA0035.namprd12.prod.outlook.com (10.162.96.173) by DM2PR12MB0048.namprd12.prod.outlook.com (10.160.99.154) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.13; Mon, 5 Sep 2016 07:00:18 +0000 Received: from DM3NAM03FT061.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::202) by SN1PR12CA0035.outlook.office365.com (2a01:111:e400:5174::45) 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; Mon, 5 Sep 2016 07:00:18 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.22) smtp.mailfrom=amd.com; ffwll.ch; dkim=none (message not signed) header.d=none; ffwll.ch; 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 DM3NAM03FT061.mail.protection.outlook.com (10.152.83.123) 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; Mon, 5 Sep 2016 07:00:17 +0000 X-IncomingTopHeaderMarker: TopHeader Received: from SATLEXDAG04.amd.com (10.181.40.9) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server (TLS) id 14.3.266.1; Mon, 5 Sep 2016 02:00:10 -0500 Received: from SCYBEXDAG01.amd.com (10.34.11.11) by satlexdag04.amd.com (10.181.40.9) with Microsoft SMTP Server (TLS) id 14.3.266.1; Mon, 5 Sep 2016 03:00:09 -0400 Received: from hr-intel.amd.com (10.237.70.71) by SCYBEXDAG01.amd.com (10.34.11.11) with Microsoft SMTP Server id 14.3.266.1; Mon, 5 Sep 2016 15:00:07 +0800 From: Huang Rui To: , Alex Deucher , Dave Airlie , =?UTF-8?q?Christian=20K=C3=B6nig?= , Daniel Vetter Subject: [PATCH] drm: modify drm_global_item_ref to avoid two times of writing ref->object Date: Mon, 5 Sep 2016 15:00:00 +0800 Message-ID: <1473058800-2964-1-git-send-email-ray.huang@amd.com> X-Mailer: git-send-email 2.7.4 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)(189002)(199003)(5660300001)(47776003)(246002)(86362001)(229853001)(92566002)(586003)(19580405001)(50226002)(48376002)(50466002)(8936002)(26826002)(8676002)(101416001)(356003)(50986999)(106466001)(2906002)(5003940100001)(87936001)(11100500001)(105586002)(626004)(33646002)(53416004)(5001770100001)(4326007)(19580395003)(7846002)(305945005)(77096005)(7696003)(36756003)(189998001)(5001870100001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0048; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:hybridsmtp02.amd.com,hybridsmtp.amd.com; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT061; 1:qZ2HXXRWtyPbGydtdiht9N4iD5fzRCd7/xY0O9deZIm9XjovkAnpL2PgVCfDUrWiMbyQ/nlSGENxjjKgZM5N3nDJ4OBgcVIhhB8eqCLxljHgK1NWNavhcOlKvoVh3eRVqykXCCJ05zzU3u+RXj9iLH/LIrtw113cpJYbDTzcIB6TO4+7Qeyddcv72v9lDAUql8XZL73VfWHox+BbNPazqDL5kjF7jd32h7w7hI41OV/aH2C2yHMbqyom5qtnQatxG9WzKZzRA3aD7AJ1cMaT2ncp5K5Y8e5djbZoYVKzkc9qzIuKLvgpfY7DVF/AUtyHinPSAWh2s/6lAltwmHOLb1blqwafHmkYMb64LwfQm5JnskHHH1McYRxBms1Akh1zO45Mway7k3IUmcRUKOu5ggZP5VVO/t8n06V5/oC/psjMfma8iclsj3N9EayPK7oKxj6SjUmzaNycp2pHR2Wfj2VV0u4AcCk+HZ4ZFqIkdU6CZ0xZfjmlOMMUds6V9QxZ7GIYDFZQ3qAbNPgAcIciZu5H+c/kTKZnRJw81rF23vAoM7w8NrBMyXVhfY7s9iPk X-MS-Office365-Filtering-Correlation-Id: 02b01a73-de28-402f-3369-08d3d55a4bbc X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0048; 2:SkXvTlRPwcBOOqWZs6oN14YEmfGY7riFuYHXewZBje9NSW9qiTCgTRyH++M8s78TutYnpYnEGc3iDk+hBkT4G9ahIlGIMSLnppKFu6v1bLKAHoDLAREaYWI4Kur37peMSUVxIBs20Nw5SA0KYI5QFThn5gi14iuEE8gWa3KHw9pbAl4o1OEyLy1UVAs0S9ka; 3:CmOxx5NViRKOgNm8I0LD9Kcv7IcQzwHNK07NqIjaDUBjrBxgnGx3xGaBv+1gzapPEuHTS8eY88aq9Ftc+v5zVKsTLae529xoNXL6ey1Autcsu3dF9VDIn3uN9JAU7tbrUZAUPXoL9naqU6yYQKy24wD1x0iR1r0lSGndQa0s66NmBsaj48dxvTc6zqXCZpjScpDlomm14HMABFG7vvIMgQOGDEomGHTrkXD9X1mcOVU= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR12MB0048; X-Microsoft-Exchange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CZCpkmjtrF4j2WzYswXXggwhKujQIDiDevBlxK2cwopIOrk0l4s8THkafASUjk8h2mm9g/kx0JWJlCSExAm6v1vyAE6pdxzjE+VbKMCX05Ei+SkCl1yzuK8KbhQAu5pN1bD+uBoYBblVRvlT1qMMXBCD8gkoaNh3qmB4Hq1QtzN+32LGs1oDIWYlAtzAwDgCvrNBlvAJAryhEpDSPQ0VGa8yeCgcu4VLDRyPkzklS4skRoqLxRW9U6SFcXXGBVppLmLU0LHDbLPb0OkNXud5Q1xjokKfBeVHkbvPwn/EqbMi7+aMhrZpvhvWgjLsIXAYUB+yvlvifCNvJ/rBBABziV+ZZ64Xa/y5WyYTXD6Xtz7e6yIPURfD3Jq9mnBZNSllhDIlZdZyi6sydpo0Orjsn+b3jN6iSAXpofAwbW5GqtSJqjpTJDay/moIKjxDM8o/7as0V7xZd9kTyyJnNqx0HNxyRp6Sx7NxP1DM0Q717eRnBcs9E8UzWi6/kmV2 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)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:DM2PR12MB0048; BCL:0; PCL:0; RULEID:; SRVR:DM2PR12MB0048; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0048; 4:BNf5A44oOhZFVuWWq3D/7Qq8qmZ2JzgBbthnRLvPpHIiUo+yFSRAE0CAH48J1dkPbtDsp1V3OFEmaVXTtaCBGwSV7Alt4Q7elfU9jhTrzeTl5YYIBSS0rArJVMNrUhufmEJihwCMP3FV+D37ZMtotvY/KHg53YY5BwWgmV6cnB5JKYlW0B1bLZzgGZpLb4WIzr6sCicSD5Cb1dVoUY0qBpwtls44b+GrACiXPLc7YBi9zK1x1g2KIcD3M1Bdlwt6PFk/N9kjkFy78JoLWd/guurdQJ2ZZ78XTahONKDH4P5BDtn1DmRJLWfjIxw+gleXAtu8sOZC3m7F3KOffDRNtM9rnnnXFlRecouQ3BWB2YARjY4XEdSSOii0u4+lUKAYnF/jrpdGMFuxGrpieh09dQgftH/C8i3aKlraqdT0HMH/qpIE5lnwLYrnkQK1J0J5fl5KZkXVWcIKL4gn1ovoxhQh+CXZE7tvh7DxQ9PwlS4JEUvKG9I+mJ0laoqEMO+I X-Forefront-PRVS: 005671E15D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR12MB0048; 23:0xEIK8qumAeHDj0xiIGuk89dvhhem6ZibnjslT34u?= =?us-ascii?Q?VnWptCbR2W67mTuie77GhwopzY6m/nDe6po+9rNlHhD5rLcHDi5NcOfRgpiu?= =?us-ascii?Q?e5/PLDdhmvdh4wfm/lgna9K1ODU1CG5olTGAwk3YXUa5BuSCsqoet0i54gJj?= =?us-ascii?Q?3Wh3Bgrmm/SVzzKhd1uItwWF7YYgxZdMph0sVvi+X4mTktWw5xPnsEeQEHN7?= =?us-ascii?Q?9GXt3jeW4+MH+rrKh+hA940+QEYUUJtgIPF+cARRHe3vgiF/12rISgNPplIu?= =?us-ascii?Q?Qn3j7IQ1L8XJrJAcPmZw4iwJCKGrOkERx0BLkChlu8hohCCZ3oYnSSSAb7/4?= =?us-ascii?Q?/8RVgMKsqqkBmStLqPoIvpiebco75jjxqlZdWOF5sXywwFjjpKGz7+QdJZ63?= =?us-ascii?Q?FSMIGfc7XxdEw7T3WXuHk5QtEICsONHrIwU6oBt1tyWLUqren+gCRUKni0PG?= =?us-ascii?Q?4NyM+7AefNTXqvUxM0UBL62uMWbNaCK1z7RJ2fNzYxRDNYA5RLJCZ3MrLM1K?= =?us-ascii?Q?cQN1Ynrr3f1s0mwybzRpNRrfacrNhua/seoFkBvMWNp1X7y0F3TUi5X+s/LE?= =?us-ascii?Q?niwzWErWxEYPYAcnWMeARfHuf23IkvqSPcnPqccfbucbbHzqkKL9apjnpjYy?= =?us-ascii?Q?2JNtzNrlDK6nzSDS9BJDv0u+7ip+1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F3Ce9TOLvy/82vtBeOp4Re4xJQazOloeFq+0Lw/HDXMa3g9YZ/e51M5iND7vMpxt92ztufs8P5nfnaR1XC90YIDSEA=; 7:BORfXdOJOQWc29rRVnsnbJVnzBuTeQJM88jxh+zRJPcCsbkPimkt88d/PLS8KatXru4ox1n5tbSNecXC4fOlzC/2UU06oN/jTIH+x7nuAzeQLVt+AQJRrda3berI2DtrLjxz7pJ5fKll5Q8EX/ejzbPCZ0zmnZ4U1IXom5Y8FAQo9DFHX3KbgKENElvXszOBZw56TzRNXsyJELqSIVokdsnLKjxHqtn35kelVVEPf9qoAiZzixHlFrbGnEHJoXqc SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0048; 20:YITKe3PdpxcjC7xNnzMI6e4rJiNlGULO+pVB2KLrR/EdSivUQa+9wiUFvnOc8EXORZUzN6vjgDoyRcDxrrl0lPaILBCHVSSToY3ZzMpGi8RuK1KPPZdLsJjEgYkElkgsnvgHlKy8vaExx2JyajldFXxdj9/sJKIqlMBW79edbgNseuMqRALgVlprhxQFynsmcBjslSVP8J/yxyeo5TuZ6wEqPfQhUI6txWZ1muK6uNaneAGA5Fhh6AFaizcVhgwJ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2016 07:00:17.8457 (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: DM2PR12MB0048 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 --- drivers/gpu/drm/drm_global.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c index 3d2e91c..3abe738 100644 --- a/drivers/gpu/drm/drm_global.c +++ b/drivers/gpu/drm/drm_global.c @@ -70,25 +70,25 @@ int drm_global_item_ref(struct drm_global_reference *ref) 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; } - - 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; out_err: mutex_unlock(&item->mutex); - item->object = NULL; + ref->object = NULL; return ret; } EXPORT_SYMBOL(drm_global_item_ref);