Thread (14 messages) flat view 14 messages, 4 authors, 2017-10-20

Re: [PATCH v2 net-next 1/2] net: dsa: lan9303: Add port_fast_age and port_fdb_dump methods

From: Egil Hjelmeland <hidden>
Date: 2017-10-19 15:42:36
Also in: lkml

On 19. okt. 2017 17:15, David Laight wrote:
From: Andrew Lunn
quoted
Sent: 19 October 2017 15:15
quoted
quoted
+/* Clear learned (non-static) entry on given port */
+static void alr_loop_cb_del_port_learned(struct lan9303 *chip, u32 dat0,
+					 u32 dat1, int portmap, void *ctx)
+{
+	int *port = ctx;
You can get the value directly to make the line below more readable:

     int port = *(int *)ctx;
You have to be a bit careful with this. You often see people
submitting patches taking away casts for void * pointers.
If they do that here, it should at least not compile...

So maybe do it in two steps?

    int * pport = ctx;
    int port = *pport;
IMHO it is best to define a struct for the 'ctx and then do:
	..., void *v_ctx)
{
	foo_ctx *ctx = v_ctx;
	int port = ctx->port;

That stops anyone having to double-check that the *(int *)
is operating on a pointer to an integer of the correct size.
Does casting to a struct pointer require less manual double-check than
to a int-pointer? In neither cases the compiler can protect us, IFAIK.
But on the other hand, a the text "foo_ctx" can searched in the editor.
So in that respect it can somewhat aid to the double-checking.

So I can do that.

One of the syntax checkers probably ought to generate a warning
for *(integer_type *)foo since it is often a bug.

	David
Egil
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help