[igt-dev] [PATCH i-g-t 5/6] tools/dpcd_reg: Make --count optional.

Rodrigo Vivi rodrigo.vivi at intel.com
Wed Sep 5 23:19:52 UTC 2018


On Tue, Sep 04, 2018 at 06:12:15PM -0700, Dhinakaran Pandiyan wrote:
> On Fri, 2018-08-31 at 21:18 -0700, Rodrigo Vivi wrote:
> > Defaults to 1 when not explicitly defined.
> > 
> > Cc: Tarun Vyas <tarun.vyas at intel.com>
> > Signed-off-by: Rodrigo Vivi <rodrigo.vivi at intel.com>
> > ---
> >  tools/dpcd_reg.c | 17 +++++++----------
> >  1 file changed, 7 insertions(+), 10 deletions(-)
> > 
> > diff --git a/tools/dpcd_reg.c b/tools/dpcd_reg.c
> > index c533401c..a141f1fc 100644
> > --- a/tools/dpcd_reg.c
> > +++ b/tools/dpcd_reg.c
> > @@ -170,7 +170,7 @@ int main(int argc, char **argv)
> >  	} cmd = DUMP;
> >  
> >  	struct option longopts [] = {
> > -		{
> > "count",      required_argument,      NULL,      'c' },
> > +		{
> > "count",      optional_argument,      NULL,      'c' },
> Passing count can be optional, but when count is passed it should
> require an argument.
> 
> From what I understand, this change makes passing an argument to count
> optional.

ops... indeed... my bad...

I will fix whenever touching this again. ;)

Thanks,
Rodrigo.

> 
> >  		{ "device",	required_argument,	NULL,  
> >     'd' },
> >  		{ "help", 	no_argument, 		&help
> > _flg,  2  },
> >  		{ "offset",	required_argument,	NULL,	
> >    'o' },
> > @@ -227,10 +227,15 @@ int main(int argc, char **argv)
> >  	}
> >  
> >  	if (cmd != DUMP && offset == INVALID) {
> > -		printf("Offset needed for this operation\n");
> > +		igt_warn("Offset needed for this operation\n");
> >  		print_usage(argv[0], 0);
> >  	}
> >  
> > +	if (cmd != DUMP && count == INVALID) {
> > +		igt_debug("count not defined, defaults to 1
> > byte\n");
> > +		count = 1;
> > +	}
> > +
> >  	memset(dev_name, '\0', 20);
> >  	snprintf(dev_name, sizeof(aux_dev) + 2, "%s%d", aux_dev,
> > devid);
> >  
> > @@ -243,20 +248,12 @@ int main(int argc, char **argv)
> >  
> >  	switch (cmd) {
> >  	case READ:
> > -		if (count == INVALID) {
> > -			igt_warn("Please specify the count in
> > bytes\n");
> > -			print_usage(argv[0], 0);
> > -		}
> >  		ret = dpcd_read(fd, offset, count);
> >  		if (ret != count)
> >  			igt_warn("Failed to read from %s aux
> > device\n",
> >  				 dev_name);
> >  		break;
> >  	case WRITE:
> > -		if (val == INVALID) {
> > -			igt_warn("Write value is missing\n");
> > -			print_usage(argv[0], 0);
> > -		}
> >  		ret = dpcd_write(fd, offset, &val);
> >  		if (ret < 0)
> >  			igt_warn("Failed to write to %s aux
> > device\n",
> _______________________________________________
> igt-dev mailing list
> igt-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev


More information about the igt-dev mailing list