Re: [PATCH net-next v7 3/9] net: txgbe: Register fixed rate clock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 09, 2023 at 10:27:28AM +0800, Jiawen Wu wrote:
> In order for I2C to be able to work in standard mode, register a fixed
> rate clock for each I2C device.
> 
> Signed-off-by: Jiawen Wu <jiawenwu@xxxxxxxxxxxxxx>

...

> @@ -70,6 +72,32 @@ static int txgbe_swnodes_register(struct txgbe *txgbe)
>  	return software_node_register_node_group(nodes->group);
>  }
>  
> +static int txgbe_clock_register(struct txgbe *txgbe)
> +{
> +	struct pci_dev *pdev = txgbe->wx->pdev;
> +	struct clk_lookup *clock;
> +	char clk_name[32];
> +	struct clk *clk;
> +
> +	snprintf(clk_name, sizeof(clk_name), "i2c_designware.%d",
> +		 (pdev->bus->number << 8) | pdev->devfn);
> +
> +	clk = clk_register_fixed_rate(NULL, clk_name, NULL, 0, 156250000);
> +	if (IS_ERR(clk))
> +		return PTR_ERR(clk);
> +
> +	clock = clkdev_create(clk, NULL, clk_name);
> +	if (!clock) {
> +		clk_unregister(clk);
> +		return PTR_ERR(clock);

Hi Jiawen,

Sorry for missing this earlier, but the above error handling doesn't seem
right.

   * This error condition is met if clock == NULL
   * So the above is returning PTR_ERR(NULL), which is a yellow flag to me.
     In any case, PTR_ERR(NULL) => 0 is returned on error.
   * The caller treats a 0 return value as success.

   Perhaps this should be: return -ENOMEM?

> +	}
> +
> +	txgbe->clk = clk;
> +	txgbe->clock = clock;
> +
> +	return 0;
> +}
> +
>  int txgbe_init_phy(struct txgbe *txgbe)
>  {
>  	int ret;
> @@ -80,10 +108,23 @@ int txgbe_init_phy(struct txgbe *txgbe)
>  		return ret;
>  	}
>  
> +	ret = txgbe_clock_register(txgbe);
> +	if (ret) {
> +		wx_err(txgbe->wx, "failed to register clock: %d\n", ret);
> +		goto err_unregister_swnode;
> +	}
> +
>  	return 0;

...



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux