From owner-svn-src-all@FreeBSD.ORG Wed Apr 17 18:36:50 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 7E95ECC2; Wed, 17 Apr 2013 18:36:50 +0000 (UTC) (envelope-from hiren.panchasara@gmail.com) Received: from mail-ea0-x236.google.com (mail-ea0-x236.google.com [IPv6:2a00:1450:4013:c01::236]) by mx1.freebsd.org (Postfix) with ESMTP id A30E7DD4; Wed, 17 Apr 2013 18:36:49 +0000 (UTC) Received: by mail-ea0-f182.google.com with SMTP id q15so872263ead.27 for ; Wed, 17 Apr 2013 11:36:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=FJREa9EEbVlhnoh/wIdDh4O1a3ysehMZxwBlptVvbuQ=; b=UvN6uUpe360j/1cc9lynjUYz/DfN2XW6tTxSedH2A/WvCWU8TFpeWQ9h5tBodTicRR ZTEEQbzU5AZhxwn+THT/9XWHJRcEafG65/ywp826UrvtKS4BvrEDxcGEKG69H2ylWHFy CCHv7ddbK6fA086Tmdg/bpPPxNB4B8jtVB7snBL3IgWbxj5BLtNntedsw2jO0FvLTU8P qjPNx7qJrn5yhKHWWfZEEDiie5FK7NpHb6zY5JZd0K85O27o+IfP5gBo/zosb79DO0dS OtIMc1MNCGbomAL4TWKXfdZbkwPMkJaDziggiCCnrpZehSYgCZYrK8vu8d5z+VKYJUmN XDkw== MIME-Version: 1.0 X-Received: by 10.14.5.137 with SMTP id 9mr20945212eel.30.1366223808825; Wed, 17 Apr 2013 11:36:48 -0700 (PDT) Sender: hiren.panchasara@gmail.com Received: by 10.15.91.72 with HTTP; Wed, 17 Apr 2013 11:36:48 -0700 (PDT) In-Reply-To: <201304171319.26560.jhb@freebsd.org> References: <201304140242.r3E2geSq094403@svn.freebsd.org> <201304161210.09058.jhb@freebsd.org> <201304171319.26560.jhb@freebsd.org> Date: Wed, 17 Apr 2013 11:36:48 -0700 X-Google-Sender-Auth: WhbUwXSFpCMhHoPaNqk2WPGExeU Message-ID: Subject: Re: svn commit: r249461 - head/sys/dev/ips From: hiren panchasara To: John Baldwin Content-Type: text/plain; charset=UTF-8 Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Apr 2013 18:36:50 -0000 On Wed, Apr 17, 2013 at 10:19 AM, John Baldwin wrote: > On Wednesday, April 17, 2013 1:15:11 pm hiren panchasara wrote: >> On Tue, Apr 16, 2013 at 9:10 AM, John Baldwin wrote: >> > On Saturday, April 13, 2013 10:42:40 pm Hiren Panchasara wrote: >> >> Author: hiren >> >> Date: Sun Apr 14 02:42:40 2013 >> >> New Revision: 249461 >> >> URL: http://svnweb.freebsd.org/changeset/base/249461 >> >> >> >> Log: >> >> Fixing a clang warning indicating uninitialized variable usage. >> >> >> >> PR: kern/177164 >> >> Approved by: sbruno (mentor) >> > >> > Hmm, I always thought that dmatags and maps were opaque types and not >> > necessarily "known" in consumers to be pointers. (Some drivers do check tehm >> > against NULL implicitly via 'if (map)' or 'if (tag)', but well-behaved drivers >> > use other means (flags, etc.) to know if they are valid.) >> >> Hi John, >> >> Would this be a better fix? We do not need to do any clean up if we >> fail to create the tag: >> >> Index: ips.c >> =================================================================== >> --- ips.c (revision 249588) >> +++ ips.c (working copy) >> @@ -578,7 +578,7 @@ >> { >> int error; >> bus_dma_tag_t dmatag; >> - bus_dmamap_t dmamap = NULL; >> + bus_dmamap_t dmamap; >> if (bus_dma_tag_create( /* parent */ sc->adapter_dmatag, >> /* alignemnt */ 1, >> /* boundary */ 0, >> @@ -595,7 +595,7 @@ >> &dmatag) != 0) { >> device_printf(sc->dev, "can't alloc dma tag for >> statue queue\n"); >> error = ENOMEM; >> - goto exit; >> + return error; >> } >> if(bus_dmamem_alloc(dmatag, (void *)&(sc->copper_queue), >> BUS_DMA_NOWAIT, &dmamap)){ > > That would be fine. I would actually prefer though that this only > call bus_dmamem_free() if the alloc succeeds, so in addition I would > make the call to bus_dmammem_free() conditional on sc->copper_queue != NULL. > Makes sense, final patch looks like this: Index: ips.c =================================================================== --- ips.c (revision 249588) +++ ips.c (working copy) @@ -578,7 +578,7 @@ { int error; bus_dma_tag_t dmatag; - bus_dmamap_t dmamap = NULL; + bus_dmamap_t dmamap; if (bus_dma_tag_create( /* parent */ sc->adapter_dmatag, /* alignemnt */ 1, /* boundary */ 0, @@ -595,7 +595,7 @@ &dmatag) != 0) { device_printf(sc->dev, "can't alloc dma tag for statue queue\n"); error = ENOMEM; - goto exit; + return error; } if(bus_dmamem_alloc(dmatag, (void *)&(sc->copper_queue), BUS_DMA_NOWAIT, &dmamap)){ @@ -623,7 +623,8 @@ return 0; exit: - bus_dmamem_free(dmatag, sc->copper_queue, dmamap); + if (sc->copper_queue != NULL) + bus_dmamem_free(dmatag, sc->copper_queue, dmamap); bus_dma_tag_destroy(dmatag); return error; } Thanks, Hiren > Thanks. > > -- > John Baldwin