svn commit: r198358 - head/sys/dev/ppbus

John Baldwin jhb at freebsd.org
Thu Oct 22 12:47:04 UTC 2009


On Thursday 22 October 2009 2:51:29 am Christian Brueffer wrote:
> Author: brueffer
> Date: Thu Oct 22 06:51:29 2009
> New Revision: 198358
> URL: http://svn.freebsd.org/changeset/base/198358
> 
> Log:
>   Check pointer for NULL before dereferencing it, not after.
>   
>   PR:		138387, 138388
>   Submitted by:	Patroklos Argyroudis <argp at census-labs.com>
>   MFC after:	1 week

In this case the '!sc' check should just be removed.  It will never be true.  
I think this is also probably true of many of the other cases you are running 
into.

> Modified:
>   head/sys/dev/ppbus/lpt.c
>   head/sys/dev/ppbus/pcfclock.c
> 
> Modified: head/sys/dev/ppbus/lpt.c
> 
==============================================================================
> --- head/sys/dev/ppbus/lpt.c	Thu Oct 22 06:17:04 2009	(r198357)
> +++ head/sys/dev/ppbus/lpt.c	Thu Oct 22 06:51:29 2009	(r198358)
> @@ -486,12 +486,15 @@ lptopen(struct cdev *dev, int flags, int
>  {
>  	int trys, err;
>  	struct lpt_data *sc = dev->si_drv1;
> -	device_t lptdev = sc->sc_dev;
> -	device_t ppbus = device_get_parent(lptdev);
> +	device_t lptdev;
> +	device_t ppbus;
>  
>  	if (!sc)
>  		return (ENXIO);
>  
> +	lptdev = sc->sc_dev;
> +	ppbus = device_get_parent(lptdev);
> +
>  	ppb_lock(ppbus);
>  	if (sc->sc_state) {
>  		lprintf(("%s: still open %x\n", device_get_nameunit(lptdev),
> 
> Modified: head/sys/dev/ppbus/pcfclock.c
> 
==============================================================================
> --- head/sys/dev/ppbus/pcfclock.c	Thu Oct 22 06:17:04 2009	(r198357)
> +++ head/sys/dev/ppbus/pcfclock.c	Thu Oct 22 06:51:29 2009	(r198358)
> @@ -150,12 +150,14 @@ static int
>  pcfclock_open(struct cdev *dev, int flag, int fms, struct thread *td)
>  {
>  	struct pcfclock_data *sc = dev->si_drv1;
> -	device_t pcfclockdev = sc->dev;
> -	device_t ppbus = device_get_parent(pcfclockdev);
> +	device_t pcfclockdev;
> +	device_t ppbus;
>  	int res;
>  
>  	if (!sc)
>  		return (ENXIO);
> +	pcfclockdev = sc->dev;
> +	ppbus = device_get_parent(pcfclockdev);
>  
>  	ppb_lock(ppbus);
>  	res = ppb_request_bus(ppbus, pcfclockdev,
> 



-- 
John Baldwin


More information about the svn-src-all mailing list