From owner-freebsd-hackers@FreeBSD.ORG Thu Sep 7 13:35:18 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5E2DE16A4E0 for ; Thu, 7 Sep 2006 13:35:18 +0000 (UTC) (envelope-from garyj@jennejohn.org) Received: from mail08a.verio.de (mail08a.verio.de [213.198.55.73]) by mx1.FreeBSD.org (Postfix) with SMTP id CBAB843E89 for ; Thu, 7 Sep 2006 13:34:20 +0000 (GMT) (envelope-from garyj@jennejohn.org) Received: from mx06.stngva01.us.mxservers.net (204.202.242.35) by mail08a.verio.de (RS ver 1.0.95vs) with SMTP id 0-0903016050 for ; Thu, 7 Sep 2006 15:34:14 +0200 (CEST) Received: from www.jennejohn.org [213.198.5.174] (EHLO peedub.jennejohn.org) by mx06.stngva01.us.mxservers.net (mxl_mta-1.3.8-10p4) with ESMTP id 2df10054.28317.049.mx06.stngva01.us.mxservers.net; Thu, 07 Sep 2006 09:34:11 -0400 (EDT) Received: from jennejohn.org (localhost [127.0.0.1]) by peedub.jennejohn.org (8.13.7/8.11.6) with ESMTP id k87DY8x2004383 for ; Thu, 7 Sep 2006 15:34:09 +0200 (CEST) (envelope-from garyj@jennejohn.org) Message-Id: <200609071334.k87DY8x2004383@peedub.jennejohn.org> X-Mailer: exmh version 2.7.2 01/07/2005 with nmh-1.0.4 To: FreeBSD Hackers In-Reply-To: Message from Ed Schouten of "Thu, 07 Sep 2006 13:38:20 +0200." <20060907113820.GO22564@hoeg.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 07 Sep 2006 15:34:08 +0200 From: Gary Jennejohn X-Spam: [F=0.0660230620; heur=0.500(-19800); stat=0.066; spamtraq-heur=0.500(2006090615)] X-MAIL-FROM: X-SOURCE-IP: [213.198.5.174] X-Loop-Detect: 1 X-DistLoop-Detect: 1 Subject: Re: Oddity in snd_uaudio(4) driver? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Sep 2006 13:35:18 -0000 Ed Schouten writes: > I was just looking through FreeBSD's snd_uaudio(4) driver, because I'm > thinking of patching it to support Xbox 360 headsets as well. I was > looking at the code to set the sample rate in > /sys/dev/sound/usb/uaudio.c. In that file there is the following code > near line 4100: > > | if (speed >= UA_SAMP_LO(asf1d) && speed <= UA_SAMP_HI(asf1d)) { > | ch->sample_rate = speed; > | return speed; > | } else if (speed < UA_SAMP_LO(asf1d)) { > | score = 0xfff * speed / UA_SAMP_LO(asf1d); > | if (score > hiscore) { > | bestspeed = UA_SAMP_LO(asf1d); > | hiscore = score; > | } > | } else if (speed < UA_SAMP_HI(asf1d)) { > | score = 0xfff * UA_SAMP_HI(asf1d) / speed; > | if (score > hiscore) { > | bestspeed = UA_SAMP_HI(asf1d); > | hiscore = score; > | } > | } > > If we would rewrite this code to something more basic, let's say we > rename 'speed' to 'x' and the UA_SAMP_ macros to some predefined > variables: > > | if (x >= 10 && x <= 20) { > | ... > | } else if (x < 10) { > | ... > | } else if (x < 20) { > | ... > | } > > Wouldn't that mean that the last portion of the code is never reached? > Looking at the code, it looks like some range check, making sure the > sample rate remains inside a certain range. Wouldn't it be enough to > remove the entire third if-statement, using a normal '} else {'? > Yeah, it seems like the last if clause should read } else if (speed > UA_SAMP_HI(asf1d)) { --- Gary Jennejohn / garyjATjennejohnDOTorg gjATfreebsdDOTorg garyjATdenxDOTde