On Thu, 2021-10-14 at 14:27 -0700, Dan Williams wrote:
> On Thu, Oct 7, 2021 at 1:22 AM Vishal Verma <[email protected]> wrote:
> 

[..]

> > +
> > +CXL_EXPORT struct cxl_cmd *cxl_cmd_new_write_label(struct cxl_memdev 
> > *memdev,
> > +               void *lsa_buf, unsigned int offset, unsigned int length)
> > +{
> > +       struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
> > +       struct cxl_cmd_set_lsa *set_lsa;
> > +       struct cxl_cmd *cmd;
> > +       int rc;
> > +
> > +       cmd = cxl_cmd_new_generic(memdev, CXL_MEM_COMMAND_ID_SET_LSA);
> > +       if (!cmd)
> > +               return NULL;
> > +
> > +       /* this will allocate 'in.payload' */
> > +       rc = cxl_cmd_set_input_payload(cmd, NULL, sizeof(*set_lsa) + 
> > length);
> > +       if (rc) {
> > +               err(ctx, "%s: cmd setup failed: %s\n",
> > +                       cxl_memdev_get_devname(memdev), strerror(-rc));
> > +               goto out_fail;
> > +       }
> > +       set_lsa = (void *)cmd->send_cmd->in.payload;
> 
> ...the cast is still nagging at me especially when this knows what the
> payload is supposed to be. What about a helper per command type of the
> form:
> 
> struct cxl_cmd_$name *to_cxl_cmd_$name(struct cxl_cmd *cmd)
> {
>     if (cmd->send_cmd->id != CXL_MEM_COMMAND_ID_$NAME)
>         return NULL;
>     return (struct cxl_cmd_$name *) cmd->send_cmd->in.payload;
> }
> 
Is the nag just from using a void cast, or having to cast at all? I
think the void cast was just laziness - it should be cast to 
(struct cxl_cmd_$name *) instead of (void *).

Having a helper for to_cxl_cmd_$name() does look cleaner, but do we
need the validation step there? In all these cases, the cmd would've
been allocated just a few lines above, with cxl_cmd_new_generic(memdev,
CXL_MEM_COMMAND_ID_$NAME) - so it seems unnecessary?
> 

Reply via email to