From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B39C2C433F5 for ; Mon, 13 Sep 2021 08:51:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BA186101A for ; Mon, 13 Sep 2021 08:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238231AbhIMIwa (ORCPT ); Mon, 13 Sep 2021 04:52:30 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:52060 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235987AbhIMIw3 (ORCPT ); Mon, 13 Sep 2021 04:52:29 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EA4DD1FFAB; Mon, 13 Sep 2021 08:51:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1631523072; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ksFxQBzI29xFmDbHIj8YRmkVKqt6DAsFXs/2K5yf7c4=; b=mWaZYv8s0o2ZUZUWpNbCiBgCD+yz9uluFPXIxp0Z2mPZuoJLxcu0peePL09mKaSTi4jk5y U5aV15eaVQYBTzOqItJCLO9hejLns0sWXroVoUvCDsAhWBLgWnf0H0vsCaupQIe928fowv 01gLcdBgKAAgBrpIWpKcWtzU1mOkFpk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1631523072; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ksFxQBzI29xFmDbHIj8YRmkVKqt6DAsFXs/2K5yf7c4=; b=L4mz27K61cl+RnXEHUjQKHIVRNv/c3yKjZWxAJSyhmjAGjDWOGWxecV34k3zLv+xDmkqgK v/cq/hq6XxXwGuCA== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id B07A5132AB; Mon, 13 Sep 2021 08:51:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id MMvSKQARP2F+FwAAGKfGzw (envelope-from ); Mon, 13 Sep 2021 08:51:12 +0000 Message-ID: <464d76e2-37f0-87f3-a9d5-2101367a8ca3@suse.cz> Date: Mon, 13 Sep 2021 10:51:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH 1/1] lib, stackdepot: Add helper to print stack entries into buffer. Content-Language: en-US To: Imran Khan , geert@linux-m68k.org, akpm@linux-foundation.org, ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.com, dvyukov@google.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-mm@kvack.org References: <20210910141001.1622130-1-imran.f.khan@oracle.com> <20210910141001.1622130-2-imran.f.khan@oracle.com> From: Vlastimil Babka In-Reply-To: <20210910141001.1622130-2-imran.f.khan@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/10/21 16:10, Imran Khan wrote: > To print stack entries into a buffer, users of stackdepot, > first get a list of stack entries using stack_depot_fetch > and then print this list into a buffer using stack_trace_snprint. > Provide a helper in stackdepot for this purpose. > Also change above mentioned users to use this helper. > > Signed-off-by: Imran Khan > Suggested-by: Vlastimil Babka Acked-by: Vlastimil Babka A comment below: > --- a/lib/stackdepot.c > +++ b/lib/stackdepot.c > @@ -214,6 +214,29 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, > return NULL; > } > > +/** > + * stack_depot_snprint - print stack entries from a depot into a buffer > + * > + * @handle: Stack depot handle which was returned from > + * stack_depot_save(). > + * @buf: Pointer to the print buffer > + * > + * @size: Size of the print buffer > + * > + * @spaces: Number of leading spaces to print > + * > + * Return: Number of bytes printed. > + */ > +int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, > + int spaces) > +{ > + unsigned long *entries; > + unsigned int nr_entries; > + > + nr_entries = stack_depot_fetch(handle, &entries); > + return stack_trace_snprint(buf, size, entries, nr_entries, 0); stack_trace_snprint() has a WARN_ON(!entries). So maybe we should not call it if nr_entries is 0 (because e.g. handle was 0) as the warnings are not useful in that case.