Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751220AbaKXW5c (ORCPT ); Mon, 24 Nov 2014 17:57:32 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:56605 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750759AbaKXW5b (ORCPT ); Mon, 24 Nov 2014 17:57:31 -0500 Date: Mon, 24 Nov 2014 14:57:52 -0800 From: Andrew Morton To: Joonsoo Kim Cc: Mel Gorman , Johannes Weiner , Minchan Kim , Dave Hansen , Michal Nazarewicz , Jungsoo Son , Ingo Molnar , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 5/8] stacktrace: introduce snprint_stack_trace for buffer output Message-Id: <20141124145752.ab64fd85.akpm@linux-foundation.org> In-Reply-To: <1416816926-7756-6-git-send-email-iamjoonsoo.kim@lge.com> References: <1416816926-7756-1-git-send-email-iamjoonsoo.kim@lge.com> <1416816926-7756-6-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: Sylpheed 2.7.1 (GTK+ 2.18.9; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 24 Nov 2014 17:15:23 +0900 Joonsoo Kim wrote: > Current stacktrace only have the function for console output. > page_owner that will be introduced in following patch needs to print > the output of stacktrace into the buffer for our own output format > so so new function, snprint_stack_trace(), is needed. > > ... > > +int snprint_stack_trace(char *buf, size_t size, > + struct stack_trace *trace, int spaces) > +{ > + int i; > + unsigned long ip; > + int generated; > + int total = 0; > + > + if (WARN_ON(!trace->entries)) > + return 0; > + > + for (i = 0; i < trace->nr_entries; i++) { > + ip = trace->entries[i]; > + generated = snprintf(buf, size, "%*c[<%p>] %pS\n", > + 1 + spaces, ' ', (void *) ip, (void *) ip); > + > + total += generated; > + > + /* Assume that generated isn't a negative number */ > + if (generated >= size) { > + buf += size; > + size = 0; Seems strange to keep looping around doing nothing. Would it be better to `break' here? > + } else { > + buf += generated; > + size -= generated; > + } > + } > + > + return total; > +} > +EXPORT_SYMBOL_GPL(snprint_stack_trace); > + -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/