Re: [PATCH 1/3] usb: gadget: storage: Add fsg_get_toc helper

From: Roger Quadros
Date: Wed Mar 09 2011 - 10:35:27 EST


On 03/09/2011 05:10 PM, ext Alan Stern wrote:

+ case 2:
+ /* Raw TOC */
+ memset(buf, 0, 37); /* Header + A0, A1& A2 descriptors */
+ buf[1] = 37; /* 4 + 3*11 */

There's no reason to do it this way. The compiler is a lot better than
you are at addition. Just put 4 + 3*11 in the assignment statement,
and in the comment explain what the numbers mean.

OK.


+ buf[2] = 1; /* First complete session */
+ buf[3] = 2; /* Last complete session */
+
+ buf += 4;
+ /* A0 point */
+ buf[0] = 1; /* Session number */
+ buf[1] = 0x16; /* Data track, copying alowed */
+ /* 2 - Track number 0 -> TOC */
+ buf[3] = 0xA0; /* Point A0 */
+ /* 4, 5, 6 - Min, sec, frame is zero */
+ /* 7 - zero */
+ buf[8] = 1; /* Pmin: 1st track number */
+ /* 9 - disc type 0: CD-ROM/DA with 1st track in mode 1 */
+ /* 10 - pframe 0 */
+
+ buf += 11;
+ /* A1 point*/
+ buf[0] = 1; /* Session number */
+ buf[1] = 0x16; /* Data track, copying alowed */
+ /* 2 - Track number 0 -> TOC */
+ buf[3] = 0xA1; /* Point A1 */
+ /* 4, 5, 6 - Min, sec, frame is zero */
+ /* 7, zero */
+ buf[8] = 1; /* Pmin: last track number */
+ /* 9, 10 - pmin and pframe are 0 */
+
+ buf += 11;
+ /* A2 point*/
+ buf[0] = 1; /* Session number */
+ buf[1] = 0x16; /* Data track, copying alowed */
+ /* 2 - Track number 0 -> TOC */
+ buf[3] = 0xA2; /* Point A2 */
+ /* 4, 5, 6 - Min, sec, frame is zero */
+ /* 7, 8, 9, 10 - zero, Pmin, Psec, Pframe of Lead out */
+ store_cdrom_address(&buf[7], msf, curlun->num_sectors);

These things could be put into a loop, instead of a separate function.

Yes loop is better than function for this case.


+ return 37;

It might be a good idea to use a variable instead of having all these
"37"s floating around. It would make future updates more reliable.

OK.

--
regards,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/