Hello. David Brownell wrote:
I think it would have been better to pass 'void *' to these methods, which they could cast to 'struct at24_data *', than to waste memory on storing 'struct at24_iface' within 'struct at24_data' just to make use of container_of() here...+static ssize_t at24_iface_read(struct at24_iface *iface, char *buf, + off_t offset, size_t count) ...Again, why "better"? Passing "void *" is generally considered worse than passing values with types that the compiler can verify. People
I think your references to the "general practice" do not fit well in this particualr case. Your use of container_of() basically nullifies the benefit of the compiler's type checking because the driver's read()/write() methods will only work correctly if passed the same "token" as given to the client via the setup() callback -- same way as if you were passing 'void *' pointing to 'struct at24_data' to setup() along with 'struct at24_iface *'. A client could have passed you a copy of 'struct at24_iface' and the driver would fail the same as being passed somewhat arbitary for the 'void *' argument. Actually, passing pointer to a copy of received "token" to driver is hardly acceptable in any case (using 'void *' would even make that harder to do :-).
WBR, Sergei _______________________________________________ Davinci-linux-open-source mailing list [email protected] http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source
