From patchwork Fri Nov 4 17:33:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Engestrom X-Patchwork-Id: 9412995 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 8FD4F6022E for ; Fri, 4 Nov 2016 17:33:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80CA62B13B for ; Fri, 4 Nov 2016 17:33:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7582C2B17C; Fri, 4 Nov 2016 17:33:41 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 9006D2B13B for ; Fri, 4 Nov 2016 17:33:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0EF6B6E0BE; Fri, 4 Nov 2016 17:33:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by gabe.freedesktop.org (Postfix) with ESMTP id BEF346E0BE for ; Fri, 4 Nov 2016 17:33:38 +0000 (UTC) Received: from HHMAIL01.hh.imgtec.org (unknown [10.100.10.19]) by Forcepoint Email with ESMTPS id CE068D17ED878; Fri, 4 Nov 2016 17:33:33 +0000 (GMT) Received: from localhost.localdomain (10.60.4.28) by HHMAIL01.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Fri, 4 Nov 2016 17:33:37 +0000 From: Eric Engestrom To: Subject: [PATCH variant 1] drm: make drm_get_format_name atomic/irq safe again Date: Fri, 4 Nov 2016 17:33:22 +0000 Message-ID: <20161104173322.20594-1-eric.engestrom@imgtec.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161104173224.GJ25290@imgtec.com> References: <20161104173224.GJ25290@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [10.60.4.28] Cc: dri-devel@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 Fixes: 90844f00049e9f42573fd31d7c32e8fd31d3fd07 drm: make drm_get_format_name thread-safe Signed-off-by: Eric Engestrom [danvet: Clarify that the returned pointer must be freed with kfree().] Signed-off-by: Daniel Vetter Note (Rob Clark): I think we need to be a bit careful about follow-up audits of callers of this.. now that you need to kfree the return value I think it is fairly easy for new patches to introduce new callers which leak the return value. We probably should have left the function as-is and introduce a new variant, or something like that. Suggested-by: Rob Clark (GFP_ATOMIC) Suggested-by: Ville Syrjälä (kasprintf) Signed-off-by: Eric Engestrom --- I'll send another variant tonight that moves the allocation to the callers (sounds cleaner to me, although there'll be some code duplication and more opportunities to make mistakes I guess). --- drivers/gpu/drm/drm_fourcc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index 29c56b4..66dcf21 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -87,9 +87,7 @@ EXPORT_SYMBOL(drm_mode_legacy_fb_format); */ char *drm_get_format_name(uint32_t format) { - char *buf = kmalloc(32, GFP_KERNEL); - - snprintf(buf, 32, + return kasprintf(GFP_ATOMIC, "%c%c%c%c %s-endian (0x%08x)", printable_char(format & 0xff), printable_char((format >> 8) & 0xff), @@ -97,8 +95,6 @@ char *drm_get_format_name(uint32_t format) printable_char((format >> 24) & 0x7f), format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little", format); - - return buf; } EXPORT_SYMBOL(drm_get_format_name);