From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ruth.realtime.net (mercury.realtime.net [205.238.132.86]) by ozlabs.org (Postfix) with ESMTP id 42A70DE17D for ; Thu, 19 Jul 2007 02:20:54 +1000 (EST) In-Reply-To: <20070718013306.GH15238@ld0162-tx32.am.freescale.net> References: <20070718013137.GA15217@ld0162-tx32.am.freescale.net>, <20070718013306.GH15238@ld0162-tx32.am.freescale.net> Mime-Version: 1.0 (Apple Message framework v624) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: From: Milton Miller Subject: Re: [PATCH 09/61] bootwrapper: Add dt_is_compatible(). Date: Wed, 18 Jul 2007 11:20:41 -0500 To: Scott Wood Cc: ppcdev , Paul Mackerras , David Gibson List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On Wed Jul 18 11:33:06 EST 2007, Scott Wood wrote: > +int dt_is_compatible(void *node, const char *compat) > +{ > + char *buf = (char *)prop_buf; > + int compat_len = strlen(compat); > + int len, pos; > + > + len = getprop(node, "compatible", buf, MAX_PROP_LEN); > + if (len < 0) > + return 0; > + > + for (pos = 0; pos + compat_len < len; pos++) { > + if (!strcmp(buf + pos, compat)) > + return 1; > + > + while (buf[pos] && pos + compat_len < len) > + pos++; This is buggy: if you are searching for "ns16550" and the compatable is "fsl,1234\0commons16550" this code will incorrectly says its compatable. Comparing pos < len instead will do the right thing, at the cost of a few iterations of the loop. > + } > + > + return 0; milton