From patchwork Mon Jul 17 13:59:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arkadiusz Hiler X-Patchwork-Id: 9845197 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 ADB6760392 for ; Mon, 17 Jul 2017 14:00:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A072828509 for ; Mon, 17 Jul 2017 14:00:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9443028497; Mon, 17 Jul 2017 14:00:57 +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 3B4C628497 for ; Mon, 17 Jul 2017 14:00:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CE4676E22B; Mon, 17 Jul 2017 14:00:55 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 706C56E22B for ; Mon, 17 Jul 2017 14:00:54 +0000 (UTC) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2017 07:00:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.40,374,1496127600"; d="scan'208"; a="1152342516" Received: from ahiler-desk1.fi.intel.com ([10.237.68.139]) by orsmga001.jf.intel.com with ESMTP; 17 Jul 2017 07:00:52 -0700 From: Arkadiusz Hiler To: intel-gfx@lists.freedesktop.org Date: Mon, 17 Jul 2017 16:59:48 +0300 Message-Id: <20170717135948.19748-1-arkadiusz.hiler@intel.com> X-Mailer: git-send-email 2.9.4 Cc: Martin Peres Subject: [Intel-gfx] [PATCH i-g-t] lib/igt_debugfs: Update documentation and clenup X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP The documentation was lying. The igt_crc_to_string() is threadsafe and does not return a pointer to an internal buffer. Actually the caller is responsible for the memory that is allocated (and they are for all the current cases), so let's put that in the doc too. While I was at it I got rid of strdup() in favor of an early allocation. Cc: Martin Peres Cc: Liviu Dudau Signed-off-by: Arkadiusz Hiler Reviewed-by: Liviu Dudau Reviewed-by: Martin Peres --- lib/igt_debugfs.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c index 80f25c6..5e4d72c 100644 --- a/lib/igt_debugfs.c +++ b/lib/igt_debugfs.c @@ -304,21 +304,20 @@ void igt_assert_crc_equal(const igt_crc_t *a, const igt_crc_t *b) * igt_crc_to_string: * @crc: pipe CRC value to print * - * This formats @crc into a string buffer which is owned by igt_crc_to_string(). - * The next call will override the buffer again, which makes this multithreading - * unsafe. + * This formats @crc into a string. Function allocates memory - the caller is + * in charge of freeing it. * * This should only ever be used for diagnostic debug output. */ char *igt_crc_to_string(igt_crc_t *crc) { int i; - char buf[128] = { 0 }; + char *buf = calloc(128, sizeof(char)); for (i = 0; i < crc->n_words; i++) sprintf(buf + strlen(buf), "%08x ", crc->crc[i]); - return strdup(buf); + return buf; } #define MAX_CRC_ENTRIES 10