On Thu, 13 Mar 2008 14:32:59 -0400 (EDT) Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote: > On Thu, 13 Mar 2008, FUJITA Tomonori wrote: > > > > > + for_each_sg(*sgl, sg, nents, i) { > > > > > > Will there be a problem in subsequent calls if *sgl has been > > > incremented but nents hasn't been changed? Maybe nents needs to be a > > > pointer also. > > > > usb_stor_access_xfer_buf doesn't check scsi_sg_count (the number of sg > > entries). It assumes that callers take care about the issue. > > > > If you want nents to be a pointer, I'm fine with it. > > If nents doesn't change then for_each_sg() won't work right. There > could be an alternative macro: Oops, I thought that for_each_sg is defined like: #define for_each_sg(sglist, sg, nr, __i) \ for (__i = 0, sg = (sglist); __i < (nr) && sg; __i++, sg = sg_next(sg)) > /* > * Loop over each sg element, stopping at the end of the chain > */ > #define for_each_sg_all(sglist, sg, __i) \ > for (__i = 0, sg = (sglist); sg; __i++, sg = sg_next(sg)) > > If you added this macro to include/linux/scatterlist.h and used it > instead of for_each_sg() then you can get rid of nents entirely. > However I'm not sure whether this would be safe. Do people sometimes > use a subset of the entries in a scatterlist? IIRC, some drivers do that (though they might use sg_next). I don't think that we add a new macro just for this function. We could change for_each_sg in the above way or we could just do in usb_stor_access_xfer_buf for (i = 0, sg = *sgl; i < nents && sg; i++, sg = sg_next(sg)) > If it isn't safe then nents would have to be passed as a pointer too. > At this stage I think it would be better to encapsulate sgl, offset, > and nents in a single structure than to pass multiple pointers. -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html